Bash output command not found
I'm facing the following problem, I created the specified condition, but when I select y for yes, everything is fine, but when I select n for I don't get annoying error output: Output: Do you agree yes (y) or no (n) N ... / myscript: [n: command not found
myscript is the name of my script The code is here:
echo "Do you agree yes (y) or not (n)"
read answer
if ( [ "$answer" = 'y' ] || ["$answer" = 'Y' ]);
then
echo -e " output for y"
done
else
echo -e " output for n "
exit 1;
Any idea how I can get rid of the output and fix the problem? thank
source to share
You missed a space in:
["$answer" = 'Y' ]
Change to:
[ "$answer" = 'Y' ]
There are other errors in the script as well. You have working code here:
echo "Do you agree yes (y) or not (n)"
read answer
if ( [[ "$answer" = 'y' ]] || [[ "$answer" = 'Y' ]]);
then
echo -e " output for y"
else
echo -e " output for n"
exit 1
fi
source to share
You are missing a space after [
in your second state. [
is actually a team, and because it is together, it literally tries to run [n
. You don't see the result with y
because the evaluation is short-circuited (i.e. the first condition is true, so there is no need to evaluate the second).
source to share