So I'm new to the OS X terminal and I'm trying to figure out how to use the if
command with the read
command.
Like this:
echo stuff:
read f
if [ "f" == "y"]
then
echo wassup
else exit
What am I doing wrong?
You're asking bash to compare whether the strings f
and y
are equivalent. Clearly, they're not. You need to use a variable substitution:
if [ "$f" == "y" ]
With this, it's asking “is the string consisting of the contents of the variable f
equivalent to the string y
?”, which is probably what you were trying to do.
You're also missing an fi
(if
backwards), which ends the if
statement. Together:
if [ "$f" == "y" ]
then
# true branch
else
# false branch
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With