Reputation: 21
Lets say I have
tmp0=2
let tmp=2*$tmp0+3 #randomm example
I can write $(cat something | cut -d " " -f$tmp)
,
but what I want to know is how to write $(cat something | cut -d " " -f$(2*$tmp0+3))
Basically I want to know how use "mathematical expression" as a flag parameter
Upvotes: 0
Views: 34
Reputation: 2671
You are actually pretty close:
$(cat something | cut -d " " -f$((2*tmp0+3)))
Note the ((
and ))
. That is how it is done. Also, take notice that I didn't need the $
on the variable. Inside a mathematical expression, variables don't need $
and it acts a lot more like C. To get the value out of it, you do need the $
on the front of ((
. If you don't need the value, but just the behavior, you can leave off the $
. Here is another example of this:
for ((i=0; i < 10; ++i)); do
echo $i
done
Since I didn't need the value out of the expression, I can leave out the $
.
Upvotes: 1