0

I have been trying to fix an error the error says "your_input command not found" even though a variable is not a command

#/bin/bash

echo "Hello, World!!"
echo "Press enter to exit."
read your_input
if [your_input == ""]
then
    echo "Bye!!"
else
    echo "You typed $your_input anyway. Bye!!"
fi

Edit: Thank you to costaparas for telling me to use [ "$your_input" == "" ]

notCoder
  • 37
  • 10
  • 3
    You need whitespace - and a `$` sign on the variable: `[your_input == ""]` => `[ "$your_input" == "" ]` – costaparas Jan 10 '21 at 13:07
  • 1
    Does this answer your question? [Getting "command not found" error while comparing two strings in Bash](https://stackoverflow.com/questions/19733437/getting-command-not-found-error-while-comparing-two-strings-in-bash) – costaparas Jan 10 '21 at 13:08
  • Btw the double quotes around the variable are crucial - the user could type arbitrary content, including for instance whitespaces and other shell metacharacters – costaparas Jan 10 '21 at 13:10
  • In bash (as opposed to sh) you can also use `[[ ]]` instead of `[ ]` and then you don't need the double quotes. – Thomas Jan 10 '21 at 13:18
  • I recommend [shellcheck.net](https://www.shellcheck.net) -- it's good at spotting common mistakes like this. – Gordon Davisson Jan 10 '21 at 16:28

0 Answers0