I have no idea where I found this little script but note the use of the case function on line 7. It is no real eye opener but it is an intelligent and fast method of parsing the command line options of the script.
#!/bin/bash
# -*- shell-script -*-for i in $*
do
case $i in
--uid|-u) OPT_UID=$2; shift 2;;
--groups|-G) OPT_GROUPS=$2; shift 2;;
--gid|-g) OPT_GROUP=$2; shift 2;;
--home-dir|-d) OPT_HOMEDIR=$2; shift 2;;
--shell|-s) OPT_SHELL=$2;shift 2;;
--non-unique|-o) OPT_NONUNIQUE=1;shift 2;;
--comment|-c) OPT_COMMENT=$2;shift 2;;
esac
doneOPTS=""
if [ -n "$OPT_$HOMEDIR" ]
then
OPTS="$OPTS -d $OPT_HOMEDIR"
fiif [ -n "$GROUP" ]
then
OPTS="$OPTS -g $OPT_GROUP"
fiif [ -n "$OPT_GROUPS" ]
then
OPTS="$OPTS -G $OPT_GROUPS"
fiif [ -n "$OPT_SHELL" ]
then
OPTS="$OPTS -s $OPT_SHELL"
fiif [ -n "$OPT_UID" ]
then
OPTS="$OPTS -u $OPT_UID"
fiif [ -n "$OPT_COMMENT" ]
then
OPTS="$OPTS -c \"$OPT_COMMENT\""
fiif [ -n "$OPT_NOUNIQUE" ]
then
OPTS="$OPTS -o"
fiCMD=adduser
UNAME=`uname`
case $UNAME in
Solaris) CMD=useradd;break;;
esac$CMD $OPTS $*
If anyone has seen this script before and knows where it came from, please let me know so i can put the credits here.
Thanks