I want to write a Bash script that checks if there is at least one parameter and if there is one, if that parameter is either a 0 or a 1.
This is the script:
#/bin/bash
if (("$#" < 1)) && ( (("$0" != 1)) || (("$0" -ne 0q)) ) ; then
echo this script requires a 1 or 0 as first parameter.
fi
xinput set-prop 12 "Device Enabled" $0
This gives the following errors:
./setTouchpadEnabled: line 2: ((: ./setTouchpadEnabled != 1: syntax error: operand expected (error token is "./setTouchpadEnabled != 1")
./setTouchpadEnabled: line 2: ((: ./setTouchpadEnabled -ne 0q: syntax error: operand expected (error token is "./setTouchpadEnabled -ne 0q")
What am I doing wrong?
This script works!
But this also works, and in addition keeps the logic of the OP, since the question is about calculations. Here it is with only arithmetic expressions:
The output is the same1:
[1] the second fails if the first argument is a string