Note: observe where I unquote the awk expression, so that the shell does expansion of $1, rather than awk.
#!/bin/sh
while [ "$1" != "" ] ; do
awk -F: '$1 == "'$1'" { print $1,$3} ' /etc/passwd
shift
done
Again, be aware of how I unquote the awk expression, so that the shell does expansion of $1, rather than awk.
#!/bin/sh
user="$1"
if [ "$user" ="" ] ; then echo ERROR: need a username ; exit ; fi
usershell=`awk -F: '$1 == "'$1'" { print $7} ' /etc/passwd`
grep -l $usershell /etc/shells
if [ $? -ne 0 ] ; then
echo ERROR: shell $usershell for user $user not in /etc/shells
fi
Other alternatives:
# See "man regex"
usershell=`awk -F: '/^'$1':/ { print $7} ' /etc/passwd`
#Only modern awks take -v. You may have to use "nawk" or "gawk"
usershell=`awk -F: -v user=$1 '$1 == user { print $7} ' /etc/passwd`
The explaination of the extra methods above, is left as an excercise to the
reader :-)
#!/bin/sh
grep -h ' /index.html' $* | awk -F\" '{print $4}' | sort -u
Unfortunately, Larry then decided to go waaaaay beyond the simple concept, by throwing in the kitchen sink, AND destroying the cleanness of the AWK language syntax, all in the name of reducing the number of keystrokes needed to accomplish something. The extra functions in perl are good. The syntax, however, is disgusting to programmers capable of touch-typing more than 20 words a minute. Having the shortest number of characters to implement something, should not be the judge of value for a language.
Here endeth the lesson