![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need suggestions about a datecheck script | tsmurray | Shell Programming and Scripting | 5 | 05-14-2008 08:23 AM |
| awk Shell Script error : "Syntax Error : `Split' unexpected | Herry | UNIX for Dummies Questions & Answers | 2 | 03-17-2008 08:16 AM |
| Performance problem with my script ...suggestions pls | vivsiv | Shell Programming and Scripting | 2 | 02-23-2008 12:25 AM |
| Suggestions Req | ravi.sadani19 | SUN Solaris | 1 | 06-01-2007 03:29 AM |
| syntex error | neer45 | Shell Programming and Scripting | 1 | 12-03-2001 01:07 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
syntex error script any suggestions
a script with prompts user and returns the value of there home directory and full name
#!/bin/bash echo "please enter your login ID" read login_id while $login_id -ne `grep $login_id /etc/passwd | cut -f1 -d:` is they anything wrong with it |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I would do it with a grep of the login_id in /etc/password
grep $login_id | awk '{print $5, $6}' |
|
#3
|
|||
|
|||
|
sorry forgot
cat /etc/passwd (in the beginniing) |
|
#4
|
|||
|
|||
|
gnom: Useless Use of cat and grep
Code:
awk -F: -v id="$login_id" '$1==id {print $5,$6}' /etc/passwd
|
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
The main problem, though, is that your while loop is incomplete, and also doesn't really appear to have a purpose. I guess you are trying to check whether the user input is a valid login ID according to /etc/passwd?
Code:
#!/bin/bash echo "please enter your login ID" read login_id if grep "^$login_id:" /etc/passwd >/dev/null then echo You guessed right else echo Wrong >&2 exit 127 fi Because we don't really want to see the output from grep when there is a match -- we only do it for the return code -- the output is redirected to /dev/null. The double quotes around the regular expression are important; otherwise the script will break if the user types something unexpected (like anything with a space in it). Of course, you cannot be sure whose account name was typed in; if you want the user's own account name, that should be available in $LOGNAME The correct syntax for a while loop is Code:
while command do commands done Last edited by era; 04-29-2008 at 11:00 PM. Reason: See also $LOGNAME; and explain while loop |
|||
| Google The UNIX and Linux Forums |