I am using below script
x=5.44 p=0 temp=$(printf "%.*f\n" $p $x) echo $temp if [ temp -gt 0 ] then echo "inside" fi
and I am getting below output with error.
5 ./temp.sh: line 6: [: temp: integer expression expected
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You need to use
$ for the shell to expand temp (As your script is written you are trying to compare the literal string
temp to the integer
0). You also should quote it:
x=5.44 p=0 temp=$(printf "%.*f\n" $p $x) echo "$temp" if [ "$temp" -gt 0 ] then echo "inside" fi
If you are using bash a better way to do it would be using bash arithmetic expression like so:
x=5.44 p=0 temp=$(printf "%.*f\n" $p $x) echo "$temp" if ((temp>0)); then echo "inside" fi
Inside of the arithmetic expression
((…)) you do not need a
$ for expansion and you cannot quote.