You need a space between [[
and "
and also between "
and ]]
. You can also drop "
around your strings when using [[
and ]]
to test - but leave the space there. Otherwise, bash
will do this:
[[yes == Yes
With the response:
[[yes: command not found...
The ||
makes it try the next part and it's here that it executes the command that becomes the "magical" loop:
yes == yes
yes
is actually a command that will repeat what you give it as an argument (it defaults to y
to be able to do yes | program
to answer all questions that program
asks with y
). It will continue to repeat the same thing until stdout
is closed (the receiver closes stdin
).
So, it will print == yes
in an endless stream.
Fix:
#!/bin/bash
echo "Found a previously saved file. Do you want to continue with this? (Yes/No)"
read -r Response
if [[ $Response == Yes || $Response == yes || $Response == y || $Response == Y ]]; then
echo "Success"
else
echo "Fail"
fi