I'm trying to run a simple If statement, but am getting errors....please advise
#!/bin/bash
echo What is your name?
read name
if $name = Peter
then echo Hey! That is my name, too!
else echo That is not a bad name either.
fi
It doesn't seem to like line 4. How do I tighten that up so that it will work correctly? Thanks, and I realize this really is UNIX child's play. I just don't have anyone else to ask.
You need to use 'test'. The shell itself calls a separate program to do the string comparison. You should probably use quotes too, though you may be able to get by without them.
#!/bin/bash
echo What is your name?
read name
if [ $name = "Peter" ]
then echo Hey! That is my name, too!
else echo That is not a bad name either.
fi