Link to home
Start Free TrialLog in
Avatar of Higante
Higante

asked on

Create a Shell for name comparison..

I am new in UNIX and I am trying to create a shell that asks for the user name and then compare this to my name.  I also would like to give a reply to the user's response that my name is the user's name too or it is a nice name too.

I am not sure what to use...should I use the if-then statement?  This is what I have started...

#!/bin/bash
name=Higante
echo My name is Higante.
echo What is your name?

read Name

case $Name in

if [$name=HIgante]

then

echo Your name is also my name?

else

echo Your name is nice too!

esac
Avatar of sunnycoder
sunnycoder
Flag of India image

Hi Higante,

You are close

you dont need a case here

if [ "$name" = higante ]
then
     echo 1
else
     echo 2
fi

Cheers!
Sunnycoder
Hi Higante,

note that $name is in quotes to prevent space from breaking the program
There is space on either side of = and around the square brackets []
Note the then and else clauses
Also note the terminating fi

Cheers!
Sunnycoder
Avatar of Higante
Higante

ASKER

sunnycoder,

You said I don't need these lines:

read Name

case $Name in


Thanks for the help.  
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial