The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 05-27-2009
cjcox cjcox is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
In pure bourne shell...


Code:
f=0
while [ $# -gt 0 ]; do
        case "$1" in
        -o?*)
                # handles things like -oValue
                o=`expr "$1" : '..\(.*\)'`
        ;;
        -o)
                # handles things like -o Value
                o="$2"
                shift
        ;;
        -f)
                # Just a flag (on/off)
                f=1
        ;;
        *)
                break
        ;;
        esac
        shift
done
echo "o=$o, f=$f"
# Loop through remaining arguments (arguments without a hyphen)
for arg in "$@"; do
        echo "$arg"
done