|
-
Sep 15th, 2002, 07:49 AM
#1
Thread Starter
Junior Member
Shell Programming.pls help
#!sh/bin
clearline=' '
continue=
clear
while [ "$continue" != "y" ]
do
echo "$clearline"
echo "Account name : \c"
read account_name
if [ "$account_name" != "" ]
then
ac=`grep ^$account_name: passwd`
if [ "$ac" != "" ]
then
a=`echo "$ac" | awk -F : ' { printf "%s",$1 } '` # $1 means prints first field
b=`echo "$ac" | awk -F : ' { printf "%s",$2 } '` # $2 means prints second field
c=`echo "$ac" | awk -F : ' { printf "%s",$3 } '`
d=`echo "$ac" | awk -F : ' { printf "%s",$4 } '`
e=`echo "$ac" | awk -F : ' { printf "%s",$5 } '`
f=`echo "$ac" | awk -F : ' { printf "%s",$6 } '`
g=`echo "$ac" | awk -F : ' { printf "%s",$7 } '`
while [ "$continue" != "y" ]
do
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo "$clearline"
echo " Account name : $a"
echo "1) Encrypted password : $b"
echo "2) UID : $c"
echo "3) Full name : $e"
echo "4) Home directory : $f"
echo "5) Startup program : $g"
echo "6) Save"
echo
echo "$clearline"
echo "Enter option : \c"
read option
case $option in
1) echo "$clearline"
echo "Password cannot be modified"
sleep 1
;;
2) echo "$clearline"
echo "3) UID : \c"
read ccc
if [ "$ccc" != "" ]
then
expr $ccc + 1 > /dev/null 2> /dev/null
if [ "$?" -eq 5 ]
then
echo "$clearline"
echo "Error : UID not numeric\c"
sleep 1
else
c=$ccc
fi
else
echo "$clearline"
echo "Error : UID empty\c"
sleep 1
fi
;;
3) echo "$clearline"
echo "4) Full name : \c"
read eee
if [ "$eee" != "" ]
then
e=$eee
else
echo "$clearline"
echo "Error : Full name empty\c"
sleep 1
fi
;;
4) echo "$clearline"
echo "5) Home directory : \c"
read fff
if [ "$fff" != "" ]
then
f=$fff
else
echo "$clearline"
echo "Error : Home directory empty\c"
sleep 1
fi
;;
5) echo "$clearline"
echo "6) Startup program : \c"
read ggg
if [ "$ggg" != "" ]
then
g=$ggg
else
echo "$clearline"
echo "Error : Startup program empty\c"
sleep 1
fi
;;
6) continue=
echo "$clearline"
echo "$a:$b:$c:$d:$e:$f:$g\c"
while [ "$continue" != "y" ] && [ "$continue" != "Y" ] && [ "$continue" != "n" ] && [ "$continue" != "N" ]
do
echo "$clearline"
echo "Save (y/n)? \c"
read continue
done
if [ "$continue" = "y" ] || [ "$continue" = "Y" ]
then
mv passwd oldpasswd
grep -v $account_name: oldpasswd > passwd
echo "$a:$b:$c:$d:$e:$f:$g" >> passwd
rm oldpasswd
exit 1
else
exit 1
fi
;;
*) echo "$clearline"
echo "Error : Option not found\c"
sleep 1
;;
esac
done
else
echo "$clearline"
echo "Error : Account not exits\c"
fi
else
echo "$clearline"
echo "Error : Account name empty\c"
fi
done
ok.......can anyone tell me what does these line means?
ac=`grep ^$account_name: passwd`
a=`echo "$ac" | awk -F : ' { printf "%s",$1 }
thanks alot!
Eat, ****, piss and its loops forever.....sick of computers?
-
Sep 15th, 2002, 02:52 PM
#2
Frenzied Member
It doesn't look c++ code to me....what language is it written in??
-
Sep 16th, 2002, 10:27 AM
#3
It's a UNIX shell script to be parsed by sh/bin - should be /bin/sh if I'm not mistaken...
The first line invokes grep, the GNU get regular expression utility, which matches a regular expression against the content of files or of any other string.
The other line is tricky.
It calls awk (which is a script language interpreter) passing the switch -F : (do a man awk in a linux shell to find out about that) and the command line arguments of the script ($1-7), then builds a pipe from the output of an echo command to the input to the awk script, meaning that if the awk script requests user input it gets the output of the echo command, which is equal to the result of the grep search.
But I don't know what this script is supposed to do as a whole.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|