![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help writing this unix script | wiggles | Shell Programming and Scripting | 7 | 12-12-2008 09:15 PM |
| help writing this unix script | wiggles | Shell Programming and Scripting | 2 | 12-12-2008 12:28 PM |
| Perl Unix Script Writing | Dinkster | UNIX for Dummies Questions & Answers | 1 | 02-01-2008 04:09 PM |
| Writing and executing a script in RTR implementation of UNIX | mahajan.anubhav | Shell Programming and Scripting | 0 | 03-16-2006 05:20 AM |
| Need help in writing a unix script | pray44u | Shell Programming and Scripting | 1 | 03-30-2005 07:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Writing Unix script to accept arguments
Hi,
This may be answered elsewhere but I wasn't entirely sure of the wording I should use to search so here we go with an attempt: I wish to make a script that will allow commands to be passed to it such as: <command> -oOPTIONS -aANOTHER -pRINT etc However I don't really know the syntax of what to do ir how to accept them with in the code. Like for example: If I want it do run a certain command if -o equals "Fred". If anyone has any help or "how to's" it would be most apprieciated. |
|
||||
|
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
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|