Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create a Shell for name comparison..

Posted on 2006-05-04
4
Medium Priority
?
229 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:Higante
  • 3
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 16607671
Hi Higante,

You are close

you dont need a case here

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

Cheers!
Sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 16607722
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
0
 

Author Comment

by:Higante
ID: 16608155
sunnycoder,

You said I don't need these lines:

read Name

case $Name in


Thanks for the help.  
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 total points
ID: 16611120
you dont need the case statement

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

read Name

if [ "$name" = "$Name" ]        >>>note both are diff variables
then
     echo 1
else
     echo 2
fi
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Screencast - Getting to Know the Pipeline

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question