Wednesday, November 9, 2011

Parsing Bash Script Command Line Arguments

http://www.digitalpeer.com/id/parsing

for i in $*
do
 case $i in
     --prefix=*)
  PREFIX=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
  ;;
     --searchpath=*)
  SEARCHPATH=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
  ;;
     --lib=*)
  DIR=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
  ;;
     --default)
  DEFAULT=YES
  ;;
     *)
                # unknown option
  ;;
   esac
done

No comments:

Post a Comment