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
Apart from the useless use of grep and cut, I guess there is something wrong with your expression as you're comparing strings and test operator should be for strings is "!=" instead of "-ne". Correct me guys if I am wrong as I am still a newbie.
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?
In the grep, I added the ^ and : to only search the first colon-delimited field; if a match is found, grep will print it and return true (so the "if" succeeds, and the "then" branch is taken); otherwise, it will print nothing, and return false (so we go into the "else" branch).
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
If you leave out do or done, you get a syntax error. (Well, if you leave out command or commands, too.) This will run command and -- like if -- check its result code; if it is true, then commands are executed, and the loop returns back to the top, and does the same thing again, until command fails to return a true exit code.
Last edited by era; 04-30-2008 at 04:00 AM..
Reason: See also $LOGNAME; and explain while loop
Hi,
Please help here for below are the correct syntax or not for elif for korn shell.
if && && && ; then
echo "ALL Servers are Running"
elif ; then
echo "gg Not Running"
fi (1 Reply)
Heyas
If you recall, not too long ago, i was asking about the GNU Autotools. The feedback on that was almost unisense, and me figured that it turned my (back then) +98% SHELL project into a +73% GROFF project... :(
Felt a bit overhelmed, specialy since i didnt actualy use or need the true... (0 Replies)
i=1
out=""
j=`expr 2 * $1`
while
do
out="$out"#""
echo $out
((i=i+1))
done
while
do
print ${out%?}
((i=i+1))
done
This script is throwing an error:
gurnish:/home/fnb/gurnish/saurabh/scripts> while1 3
expr: 0402-050 Syntax error.
# (6 Replies)
Hi All,
This is for WPAR monitoring shell script, earlier opened thread was closed, had to open a new thread, as suggested I have used script as below, But am trying to get the output in below format, need suggestions with it. Below is the lswpar output, required output format.
... (7 Replies)
Hello, I am new to Shell programing.
I want to add two numbers & show result. command I use are as under
Echo Enter the two numbers
read number
d1 = ` expr $ num%10`
num = `expr $ num/10`
d2 = ` expr $ num%10`
num = `expr $ num/10`
sum = $ d1 + $ d2
echo the sum is $ sum
I am getting... (1 Reply)
Hi,
I have a series of BASH shell scripts that process data. All of the scripts are controlled by a "master" script, where users specify their processing parameters. The sub-scripts, and the order they are called, depend on the values of these user-specified processing parameters. This method... (1 Reply)
Hello, beginner bash scripter here.. I was able to write a script and it works just fine. I'm just wondering if someone could chime in or any suggestions to make it cleaner or tighter so to speak. I have a disk to disk backup solution which uses 250GB disks. When one gets full I just po in a new... (7 Replies)
I'm currently running a script that checks to see if a laptop is on the network, and if it is it backs up, if not it retries it later.
Anyway, our backup scheduling has changed. I need to check if today's date is the Thursday after the first Wednesday of every month. This is made slightly more... (5 Replies)
Hi ,
I have included my script below, pls read thro this req. I want my script to run for every hour , the problem is I CANNOT USE CRONTAB which is prohibited inside the company. My script does what it is supposed to do (to determine the memory and then send a email if it crosses a certain... (2 Replies)
hi
I am try to run following script using c-shell but i get the following syntex error:-
----script---
---------------------------------------------------------------------------------
#!/bin/csh
echo "system monitor"
echo "
1) system paging
2) system file inf.
3) system... (1 Reply)