Shoutout to http://www.digitalpeer.com/id/parsing for this easy way of parsing commandline args in bash: for i in $* do case $i in -p=*|--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
Archive for the ‘Bash Scripting’ Category
Bash scripting – Parsing commandline args
Posted in Bash Scripting on January 28, 2010| Leave a Comment »