I have a problem with a bash script on raspberry pi:
x='gpio -g read 22'
if [ $x -ge 1 ]
then
gpio -g write 23 1
fi
The error is integer expression expected
. Why?
bashcommand-substitutionshell-script
I have a problem with a bash script on raspberry pi:
x='gpio -g read 22'
if [ $x -ge 1 ]
then
gpio -g write 23 1
fi
The error is integer expression expected
. Why?
Best Answer
That's because you are checking whether the string
gpio -g read 22
is greater than 1. Sincegpio -g read 22
is not a number, you get that error.You don't explain what you are trying to do but I'm guessing you want to compare the output of the
gpio
command. To do that, you need to enclose the command in$()
or backticks (``
):Or, more simply:
The assignment
foo='command'
doesn't runcommand
. The variablefoo
takes the value of the stringcommand
and not its output.