While Loop assistance.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers While Loop assistance.
# 1  
Old 02-05-2008
While Loop assistance.

I am trying to make a simple while loop which reads in a text until the person types quit. And it's not working, and I know it's a rather simple problem I just can't seem to understand... Once again all assistance is greatly appreciated.

#!/bin/sh
astring="z"
while astring!="quit"
do
read astring
if astring="z"
then
astring="hello my name is Gsmith and I have 5 dollars"
echo $astring
else
echo "Never again"
fi
done
# 2  
Old 02-05-2008
Tools perhaps the issue was with variable names

try the following:

#!/bin/sh
astring="z"
while [ $astring != "quit" ]
do
read astring
if [ $astring = "z" ]
then
bstring="hello my name is Gsmith and I have 5 dollars"
echo $bstring
else
echo "Never again"
fi
done
# 3  
Old 02-05-2008
Once again you've saved my day!

yes that was in fact the problem... odd how that worked. I will have to mind my variables much closer.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need assistance on ACL

Hi Friends, I went through the ACL threads that were posted in the past but none were matching to my requirement . Hence starting a new thread . Challenge : user : a group : Test1 user: b group: Test2 Say under user a i create dir /tmp/debug with the privilege of 755 and also... (3 Replies)
Discussion started by: leobreaker
3 Replies

2. Shell Programming and Scripting

Assistance to use ls and GREP

Hi We have several folders and subfolders in a heirarchy, representing clients and files we send to them. Files that are not processed are placed in reject folder. I am able to run a LS that will scan all these folders, and ones that show entries (rejected files) are seen here. I am looking for... (8 Replies)
Discussion started by: cdc01
8 Replies

3. UNIX for Dummies Questions & Answers

Need assistance on using ldapsearch

Never knew of this command ldapsearch, but I would like to use it to lookup a single user and return where their office is. Is this possible? I'm totally starting from scratch. I already saw some of the gurus say read the man page, which is pretty greek when you don't know the details of... (1 Reply)
Discussion started by: srhadden
1 Replies

4. Shell Programming and Scripting

Need assistance with sed

Hi All, I need your assistance, I would like to replace all lines beginning with the word "begin" with the below text: Device | IPMB0-A | IPMB0-B Board Address |Sent SentErr %Errr |Sent SentErr ... (9 Replies)
Discussion started by: Dendany83
9 Replies

5. Shell Programming and Scripting

Loop assistance, getting array of random numbers and feeding to a command, how-to?

Hi all, I need a little assistance to complete the following script. I would like to take a file with a single number on each line and for each number, run it through a command. The loop will terminate once all numbers have been checked. Here is what I have thus far... COUNTER=`wc -l... (2 Replies)
Discussion started by: boolean2222
2 Replies

6. Solaris

hardware assistance

Hoping someone can help clarify what I need. At present I have a Sun Ultra 2 with two ultrawide scsi cards and 2-12 drive multipacks (one multipack to one card, the other multipack to the other card), 2 Sun Ultra 10's, and a Sun E4500 with a differential scsi card connected to a half filled... (4 Replies)
Discussion started by: paulbryant
4 Replies

7. Shell Programming and Scripting

I need an assistance

I have a school project to create a shell program same as calendar i must create a txt file with celebrations with vi i know this but the problem is i don't know awk and grep. The object of object is to create a program who read a date an appear the celebration. Can you help me please !!!... (1 Reply)
Discussion started by: mytilini boy
1 Replies

8. UNIX for Dummies Questions & Answers

Assistance needed.

the command "nawk" returns the error command cannot be found in my unix system. Is there a specific library i need to have to use this command? I tried, the whereis command and it returns nothing. if there is nothing to do, what command can i use to replace this nawk command? Appreciate some... (4 Replies)
Discussion started by: 12yearold
4 Replies

9. UNIX for Dummies Questions & Answers

Need Assistance

I have two questions I am struggling with... How do the programs p1, p2, and p3 need to handle their standard files so they can work like this: p1 | p2 | p3 ? What exactly is this command supposed to do? $ kill -QUIT %1 & This command below? $ sort -o emp.lst emp lst & Any... (1 Reply)
Discussion started by: yahoo14
1 Replies

10. Shell Programming and Scripting

regexp assistance

i have a list of text a b c d e My desired output is 'a','b','c','d','e' any advise? My file was actually in excel format, i copied out the column into notepad. I am not sure if the \n exists in between. (2 Replies)
Discussion started by: new2ss
2 Replies
Login or Register to Ask a Question