Cover V09, I07
Article
Listing 1
Listing 2
Listing 3

jul2000.tar


Listing 3: keyword.sh

# keyword=value demo
# handles examples as F1=60, F1 =60, F1= 60
while [ "$#" -gt 0 ]
do 
   case $1 in
      F1)  # spaces after keyword
           shift; equ=$1
           # spaces after equal sign
           if [ "$equ" = "=" ]
           then
              shift
              f1arg=$1
           else # no equal sign, but maybe =value
              ret_val=`echo "$1" | awk '{ if (beg=index($0,"=") )
                           print 1
                        else 
                           print 0 }'`   
              if [ ret_val -gt 0 ]
              then # get rid of the equal signs
                 f1arg=`echo "$1"|tr -d "=" `
              else
                 echo "Illegal command-line option " 
                 exit 1;
              fi
           fi
           shift
      ;;

      F1*) # no spaces after key word
           # string may look like KEYWORD= value
           # if last character is an equal, next field is parameter
           ret_val=`echo "$1" | awk '{ if (beg=index($0,"=") )
                   { 
                   len=length($0)
                   if (beg == len)
                     print 1
                   else 
                     print 0
                   }  
                   else print 0 }'`   
           if [ $ret_val -gt 0 ]
           then # next field is the days to keep
              shift; f1arg=$1
           else # field is probably KEYWORD=value
              ret_val=`echo "$1" | awk '{ if (beg=index($0,"=") )
                      { beg++ # bump beginning
                        len=length($0)
                        num=substr($0, beg, len)
                        print num # print string after equal sign
                        }  
                      else print '\0' }'`   
              if ! [ -z "$ret_val" ]
              then
                 f1arg=$ret_val
              else
                 # found parameter, but no equal sign
                 echo "Illegal command-line option " 
                 exit 1
              fi

           fi
           shift
      ;;

      *) echo "Command-line option not defined" 
         exit 1
         ;;
   esac
done
if ! [ -z "$f1arg" ]
then # echo if set
   echo $f1arg
fi