Script to see if a username is valid.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to see if a username is valid.
# 1  
Old 11-07-2011
Script to see if a username is valid.

This is my task:

  1. The argument enter on the command line is a first and last name ( for example: "John Smith").
  2. If the argument is a validly formatted name, you display The "name enter" is valid to standard out.
  3. If the argument is not a validly formated name, you display The "name enter" is not valid to standard out
For Example,
$ valid_name "John Smith"
John Smith is valid
=========
$ valid_name "John smith"
John smith is not valid
=========
$ valid_name "John"
John is not valid
==========
$ valid_name "jOhn Smith"
jOhn Smith is not valid
===========
$ valid_name "John sMith"
John sMith is not valid






This is what I have so far:
Code:
if [ $# -ne 1 ]
then echo usage: enter 1 agrument
exit 1
fi
if [ "$1" = $( ]
then echo $1 is valid
else echo $1 is not valid
fi

I need to use grep or sed somehow right? I cannot figure this out for the life of me.

Please help.

---------- Post updated at 10:17 PM ---------- Previous update was at 08:33 PM ----------

Now I have this but I need help with the pattern to make all the examples work:
Code:
if [ $# -ne 1 ]
then echo usage: enter 1 agrument
exit 1
fi
if [ "$1" = "$(echo $1 | grep '[A-Z]*\ [A-Z]*')" ]
then echo $1 is valid
else echo $1 is not valid


Last edited by fpmurphy; 11-08-2011 at 12:40 AM.. Reason: code tags please!
# 2  
Old 11-08-2011
Is this a homework?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script accepting variables in valid number format

Hi Experts I would like to ask if there is a way to validate if the variable passed is in this kind of sample format "06-10" or "10-01". It was really a challenge to me on how to start and echnically the "6-10" stands for "June 10" and "10-01" stands as "October 1", overall it needs to have ... (3 Replies)
Discussion started by: ersan-poguita
3 Replies

2. Shell Programming and Scripting

How to send Two different password in Single script, having same username..?

Hi Team, i want to input two password for single node like pass1/pass2 one of the pass1 is working some node and pass2 is working for some nodes . For nodes having pass1 i have to run different script and for nodes having pass2 i have to run different script Sooo how can put two pass... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

3. Shell Programming and Scripting

Need a script to check if an argument is valid shell variable

I need a script that should print 'yes' if the argument is a valid shell variable name else 'No' if it is not a valid shell variable. A valid one begins with an alphabet or percentage (%) character and is followed by zero or more alphanumberic or percentage (%) characters. For example: $... (6 Replies)
Discussion started by: pingiliarjun
6 Replies

4. Shell Programming and Scripting

Q: grab email username from script

Hi all, I want to set up a script to email a person to confirm another program is running but i wish to avoid having to customise the script for each individiual. I am ok with what i need to do except i need to get the first and last name of the user to construct an email address to send to.... (6 Replies)
Discussion started by: KlintJ
6 Replies

5. Shell Programming and Scripting

How to check the user input to be valid using shell script?

How to check the user input to be valid using shell script? The valid input is in the format like as follows. 1. It can only have r,w,x or a hyphen and nothing else. 2. ensure the r, w, x are in the correct order. for example: rwxr-xr-x is a valid format. Thanks (5 Replies)
Discussion started by: hyeewang
5 Replies

6. Shell Programming and Scripting

sh script to get unix username of person executing it

Hi, I am writing a script, and I need to incorporate some logic where I can find out the unix username of the person who is executing the script. The issue is , a particular user could have "sesu" ed into a group id. for eg. root, and then executed the script. In that case, instead of root,... (5 Replies)
Discussion started by: neil.k
5 Replies

7. Shell Programming and Scripting

Need to modify a file of different username through script.

Hi ! All I want to write a script where, it will open a new shell with a username / pwd and modify a file of same username and exit. example: 1. UserA 2. UserB- FileB ScriptA -> su UserB -> Modify FileB -> Exit ScriptA Can somebody give me a direction , on how to... (2 Replies)
Discussion started by: dashok.83
2 Replies

8. Shell Programming and Scripting

username password in script

Can we write a script to telnet to a unix server from unix with the username and password hardcoded in the script?? something like ssh a@b -p password ??? (5 Replies)
Discussion started by: roshanjain2
5 Replies

9. Shell Programming and Scripting

Get username in script

how would i go about getting the username of the person currently logged in, and then using the username in a shell script? i've tried variations of user=whoami , 'whoami' , $whoami , and none of the above work :( lol I'd like to get the username to then mount a network share such that the... (9 Replies)
Discussion started by: willc0de4food
9 Replies

10. Shell Programming and Scripting

Checking the valid paths in the shell script

Hi i am using a shell script for renaming the files and placing in the remote location(FTP) my code is: cd $1 day=$(date +%d) for i in `ls -1 BBW*` do last=`tail -1 $i` pat=`expr "$last" : '.*(\(.*\)).*'` pat=`echo $pat | sed 's/ /_/'` pat=$pat$day mv $i $pat rm -f $day done... (3 Replies)
Discussion started by: srivsn
3 Replies
Login or Register to Ask a Question