b= printf %.0f $a
This line sets the value of b
to nothing for the duration of the printf command, which sends its output to stdout
echo $b
This prints a blank line.
You must not put whitespace around the =
in an assignment, and to store the output of a command into a variable, you use this syntax:
b=$( printf %.0f $a )
You're getting the error because $b
is empty, and this is what bash sees:
if [ -ge 1 ] &&[ -le 9 ]; then
-ge
is expecting operands on both the left and the right, and it doesn't see one.
With bash, you should (almost) always prefer [[ ... ]]
over [ ... ]
-- the double bracket form is not fooled by variables containing empty strings.
You should always quote your "$variables"
-- unless you know exactly when to not quote them.