loop needed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop needed?
# 1  
Old 07-04-2008
loop needed?

Hi All, thanks in advance for any help you can give me.

I'm trying to get some error checking of a username in my shell script. While I have that part under control, at the moment my script just exits if the username entered doesn't match the correct syntax.

I've been googling to try and figure it out but I'm missing something. I can get an endless loop of my 'echo' statements but I go no further. I'm sure it's something stupidly simple but I just can't pick it.

This is part of the script I have so far:

Code:
echo -n "Enter Username (e.g. abcd1234): "
read username
echo "Entered Username:" $username

if
echo "$username" | grep -o "[wiki]:alpha:[/wiki]\{4\}[0-9]\{4\}"
     then
             echo good username
     else
             echo bad username
             exit(65)
fi

I also want to know if the exit65 is the correct usage.

-- Adarii

Last edited by adarii; 07-04-2008 at 03:25 AM..
# 2  
Old 07-04-2008
Have a look at the script in this thread which does a similar thing:

https://www.unix.com/shell-programmin...d-command.html

The correct syntax for the exit to return a code 64 would just be exit 65.
# 3  
Old 07-04-2008
Thanks so much for your prompt response, unfortunately I'm totally script newbie and I'm pretty lost when I look at that guys script

I figured it would be some kind of while loop waiting for a certain criteria to be met before it exited out but how I set that criteria is wehre I'm lost.

If anyone who can help would explain it in longhand that'd be great. I'll keep looking in the mean time Smilie

Hope everyone has a good weekend
# 4  
Old 07-04-2008
Try this (untested):

Code:
until echo "$username" | grep -o "[[:alpha:]]\{4\}[0-9]\{4\}"
do
    echo -n "Enter Username (e.g. abcd1234): "
    read username
    echo "Entered Username:" $username
done

# 5  
Old 07-04-2008
Absolutely perfect thankyou so much Smilie

Now I know about the 'until' command Smilie

Woohoo!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

2. Shell Programming and Scripting

Alternative to the loop is needed

I have a file containing ids like this (file1): c9e2c3c6c100000000460000c02000803c63e529c3f5f5f0 c9e2c3c6c100000000460000c02002813c63e539c3f5f5f0 c9e2c3c6c100000000460000c02002ee3c63ebb1c3f5f5f4 c9e2c3c6c100000000460000c020042f3c63e549c3f5f5f0 These ids are present in muiltiple files named:... (4 Replies)
Discussion started by: niladri29
4 Replies

3. Shell Programming and Scripting

Help needed: Adding columns in csv file in loop

Hi Everyone: My shell script creates multiple csv files (~30) in for loop. I want to compile (or merge) 3rd column from each (all) of these files to another file (in loop). Please help. Thanks. (3 Replies)
Discussion started by: smap007
3 Replies

4. UNIX for Advanced & Expert Users

'for' loop advice needed....!!

Scenario: Command used to capture IPs on a host: /usr/sbin/ifconfig -a | grep "inet" | egrep -v "inet6|0.0.0.0|192.168.100.2" | awk '{print $2}' Following for loop used to capture interface names: for INTERFACE in `/usr/sbin/ifconfig -a | nawk '$1 ~ /:$/ && $1 {sub(":$", "", $1); print... (3 Replies)
Discussion started by: ak835
3 Replies

5. Shell Programming and Scripting

'for' loop advice needed ....!!

/usr/sbin/ifconfig -a | grep "inet" | grep -v "inet6" | grep -v "127.0.0.1" | grep -v "0.0.0.0"|grep -v "192.168.100.2" | awk '{print $2}' I use above command to get IP addresses on AIX boxes.Values coming here are set to a variable "Host IPs.IP Addresses" in my fingerprinting engine. ... (4 Replies)
Discussion started by: ak835
4 Replies

6. Shell Programming and Scripting

While Loop Syntax help needed

Hi everyone, Can ny1 help me out regarding while loop arguments i.e. what does -gt -ge -lt -le means? actually i am new to while loops (2 Replies)
Discussion started by: jojo123
2 Replies

7. Shell Programming and Scripting

if loop help needed

Dear All, Please help me out for the below query echo 'please input file type (i.e file1,file2,file3,file4): ' read a cat hello.wri | grep $a | wc -l > temp1.wri cat hello.wri | grep $a | wc -l > temp2.wri cat hello.wri | grep $a | wc -l > temp3.wri cat hello.wri | grep $a | wc -l >... (1 Reply)
Discussion started by: jojo123
1 Replies

8. Shell Programming and Scripting

Script - Filter data - repeated loop - Help needed...

Dear Friend, I need a help for the below problem.. Can anyone suggest me to do... Input file data: rule { name=mainrule filt=pos loc { x=right + 660 y=top - 3100 } object_kind= DRAW ... (15 Replies)
Discussion started by: vasanth_vadalur
15 Replies

9. UNIX for Dummies Questions & Answers

For loop help needed

Hi there, i want to direct the out put return from the FOR loop statement to any log file. code copied below. for file in `ls *.in` do ... ... done if there is no file then i need to write the log to one file. Thanks Arun (3 Replies)
Discussion started by: arund_01
3 Replies

10. Shell Programming and Scripting

NEED HELP PLZ! While Loop script needed!

PLZ Help us. I need to write a "while loop" script in borne shell to go into the /tmp directory every second and update me with the size of every file in the temp directory. My boss sprung this on me today and I have to have the script done by tomorrow. I can't loose my job, cause my wife and I... (1 Reply)
Discussion started by: scoobydoo
1 Replies
Login or Register to Ask a Question