![]() |
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 |
| Help in getopts | chella | Shell Programming and Scripting | 4 | 11-02-2007 01:09 AM |
| getopts help | GrepMe | Shell Programming and Scripting | 3 | 06-20-2007 11:47 AM |
| help in getopts | problems | Shell Programming and Scripting | 1 | 05-04-2006 11:07 PM |
| getopts | yerra | Shell Programming and Scripting | 5 | 03-26-2005 10:43 AM |
| getopts | Shell Programming and Scripting | 3 | 12-05-2002 07:42 PM | |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Here is an example of using multiple optional arguments. All of them are in OPTARG.
Code:
#!/bin/ksh
# foo is shell function in this example - it could be a separate script
foo()
{
echo "foo: I got $# options"
echo " they are $@"
}
while getopts a: opt
do
set -A arr $OPTARG
case $opt in
a) echo "option -a"
for i in $OPTARG
do
echo "subargument = $i"
done
echo "running foo with these options"
foo $OPTARG
exit 0 ;;
\?) echo "\nUsage: $0 [-a <option>]" >&2
exit 2;;
esac
done
Quote:
|
|
|||||
|
so you mean to tell me ALL I needed to do this whole time was encase all the arguments in quotation? It works perfect with them!... but is there a proper way to omit the quotes?
..... ??... ..... EDIT: This code block, if i give arguments to bad options, it immediatley exits the program instead of pressing onward Code:
#! /bin/bash while getopts r:f:c: o do case "$o" in r)sh right.s $OPTARG;; f)sh findtext.s $OPTARG;; c)sh count.s $OPTARG;; ?)echo "Useage: -r ''[#] [#] [#]'' " echo " -f ''[key] [filename]''" echo " -c ''[filename]''";; esac done did I miss something? Last edited by TurboArkhan; 03-05-2008 at 07:52 PM.. |
|
||||
|
Hello
Try indirect expansion with ! First set A3 to the index of the 3rd argument and at the end increment OPTIND by 2 r) A3=$(( $OPTIND + 1 )) sh right.s $OPTARG ${!OPTIND} ${!A3} OPTIND=$(( $OPTIND + 2 )) ;; |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|