I have written this bash script which is meant to check your input to see if it is y
, n
or something else (this will be part of a larger project):
#!/bin/bash
echo "Have you updated the PATH variable in your .bashrc file yet? [y/n]"
read response
if [$response = "y"]; then
echo "Checkpoint passed"
set $checkpoint = "t"
elif [$response = "n"]; then
echo "Please set the PATH variable in your .bashrc file before running this script."
set $checkpoint = "f"
else
echo "Please only use 'y' and 'n'."
set $checkpoint = "f"
fi
But every time that I run it I get an error similar to this one no matter what I put in:
Have you updated the PATH variable in your .bashrc file yet? [y/n]
y
./snbjdkhome: line 6: [y: command not found
./snbjdkhome: line 9: [y: command not found
Please only use 'y' and 'n'.
So what is wrong with my code? (I am very new to shell scripting.)
case
(preferably withselect
). – muru Mar 16 '15 at 02:33