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
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
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
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
ASKER
sunnycoder,
You said I don't need these lines:
read Name
case $Name in
Thanks for the help.
You said I don't need these lines:
read Name
case $Name in
Thanks for the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are close
you dont need a case here
if [ "$name" = higante ]
then
echo 1
else
echo 2
fi
Cheers!
Sunnycoder