digital adj. Having digits.     peer n. A comrade; a companion; a fellow; an associate. inmotion    
   
Recent Articles
Stop DNSMasq From Forwarding Local Hostnames
Saturday, September 25, 2010
Securing your Wireless LAN
Wednesday, August 18, 2010
Some tips and things you might not know about your wireless network.
Using Different Subversion Client Versions
Wednesday, August 18, 2010
Handling a Subversion Repository URL Change
Sunday, May 3, 2009
If your repository URL changes, you can use the following command to fix existing snapshots.
vfat Mounts Default to Lowercase Shortnames
Tuesday, April 21, 2009
I want a "this is brain-damage" quote from Linus for this mess.
VirtualBox or VMWare Virtual Machine at Login
Sunday, April 12, 2009
How to start a virtual machine in X when a user logs in.
Dialog Progress Bar Through Pipe
Sunday, April 12, 2009
How to use dialog to display a script progress bar and communicate progress to it through a named pipe.
Mount JFFS2 Image
Saturday, October 25, 2008
Example of how to mount a JFFS2 image using mtdblock.

Never mistake knowledge for wisdom. One helps you make a living; the other helps you make a life.
- Sandra Carey

Projects-Misc Scripts-Parsing...

Parsing Script Command Line Arguments

Wednesday, January 19, 2005 by digitalpeer

An easy way to parse command line options with or without values in a Bash or variant script file.

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

Comment Thursday, August 28, 2008 by  David C. Rankin, J.D.,P.E.
excellent, with a quick mod you can easily handle both long and short options as well:

-p=*|--prefix=*)
Comment Thursday, February 18, 2010 by  anonymous
Thnxm this really helped!
Comment Monday, May 2, 2011 by  bundacia
You can also use parameter expansion instead of the echo $i | sed... trick so this:

PREFIX=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`

can be replaced with this:

${i#*=}
Comment Monday, May 2, 2011 by  bundacia
Sorry, that last line should read:

PREFIX=${i#*=}

Submit Comment to This Article
Please post a comment if you have something to add, find something wrong, or would like more information on the topic at hand. Do not use the comment form to contact the author about unrelated concerns!

Name: Email (optional):
Enter verification number here: