The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Carreer:Networking Programming in Unix (C programming Language) vibhory2j UNIX for Dummies Questions & Answers 5 09-05-2008 04:57 PM
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 3 09-14-2006 07:23 AM
c programming or unix programming!? moxxx68 High Level Programming 1 03-30-2004 05:53 AM
programming question from a newbie, please help milenky High Level Programming 1 10-11-2002 07:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-05-2006
Registered User
 

Join Date: Mar 2006
Posts: 1
Wink Programming Newbie Chick

OK, so I'm trying to finish my last individual assignment for this course, and it's the first time I've visited a forum (I've actually understood UNIX up to this point). I am having trouble with this one. I have to write a program that prompts the user to type their first name and stores it in a variable, then prompts for their last name and stores it as well, and then displays "You entered LastName, FirstName. Is that correct?" and if the user enters y or yes, it replies "Thank You!" or if the user enters n or no, the script restarts, prompting for the user's first name again. Here's what I have so far:

#!/bin/bash
while [ $confirm != "y"]
do
echo Please enter your first name:
read fname
echo Please enter your last name:
read lname
echo You entered $lname, $fname. Is that correct?
read confirm
done
echo Thank You!

So far, I am getting an error message in the second line, referencing the first "[" symbol. Not sure why. I also don't know how to test for y and yes, right now it only tests for the y character. I need to also test for yes. Please help! It's probably something really stupid, but I'm just new to this! Thank you so much for any hints or anything at all. Have a good night.

MetalGoddess
Reply With Quote
Forum Sponsor
  #2  
Old 03-05-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
The rules say
(6) Do not post classroom or homework problems.

But since you have done most of the work, I will point out a syntax error that you have.

Code:
while [ $confirm != "y"]
should be
Code:
while [ $confirm != "y" ]
Notice the whitespace after "y"
Reply With Quote
  #3  
Old 03-17-2006
Registered User
 

Join Date: Jan 2006
Posts: 59
Just link the second condition with -o as

while [ $confirm != "y" -o $confirm != "yes" ]
....
Reply With Quote
  #4  
Old 03-18-2006
dsbeerf's Avatar
Registered User
 

Join Date: Dec 2005
Location: Chicago, IL USA
Posts: 58
I noticed you said you are a programming "newbie" in UNIX. So I think I need to say the following.

The '[' used to be the same as the program "test". It is now a shell builtin, with basically the same function. The '[' character is also recognized by the shells (sh|ksh|bash) as a 'special character', and as such, requires you to 'finish' the syntax with the ']' character. The way to do this is to have the ']' stand-alone, separate (by whitespace) from other characters (or with a 'defined' termination character, like --> '];' ).
THAT is why you got the error you were getting. The shell could not find a terminating ']' character.
The '[' is "test", but also an "open bracket". It needed to find a "close bracket" to complete the syntax.

B.T.W.: the tests for 'y', 'Y', 'yes', 'Yes', or 'YES' could more easily be accomplished with a 'case' statement. Easier to understand, and easier to adjust in the future, too.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0