if [`read -n1 -s`='y']
is causing
./bzfsctl.sh: line 17: [=y]: command not found
Even
if [1=1]
produces:
./bzfsctl.sh: line 17: [1=1]: command not found
EDIT After properly adding in the spaces get
./bzfsctl.sh: line 16: [: -eq: unary operator expected
with
if [ `read -n1 -s` = 'y' ]
then
echo 'killing process ...'
else
echo 'Aborted'
fi
You need to be careful with the spaces in your commands.
All four of these spaces are necessary.
If you want to read a single char and test it:
When you write
if something ; then ...the shell executessomethingand then acts depending on the return code of that command.[isn’t “syntax”, it’s a program (or shell built-in), that is also calledtest.So:
actually runs the executable (or built-in)
[with the arguments$a,=,$band].If you don’t put the brackets, you need the thing between the
ifand;to be a regular executable command that returns 0 on success.