|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
getopt
Code:
#!/bin/sh
set -- `getopt "abco:" "$@"`
a= b= c= o=
while :
do
case "$1" in
-a) a=1;;
-b) b=1;;
-c) c=1;;
-o) shift; o="$1";;
--) break;;
esac
shift
done
shift # get rid of --
# rest of script...
# e.g.
ls -l $@This code works well until there are filenames with spaces, even getopt -s sh doesn't help. How this problem could be resolved? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
space are evil. the easy way to to prevent them by quoting on the commandline.
|
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
This wil not help as far as quoting will be removed by getopt
|
|
#4
|
|||
|
|||
|
hi all...
i have come across the posting .... can any one please explain the code.. set -- `getopt "abco:" "$@"` a= b= c= o= while : do case "$1" in -a) a=1;; -b) b=1;; -c) c=1;; -o) shift; o="$1";; --) break;; esac shift done shift # get rid of -- # rest of script... # e.g. ls -l $@ ..... what will set -- `getopt "abco:" "$@"` do and so on. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Quote:
The Bourne Shell set command sets positional parameters to the getopt's output, i.e. if getopt returns something like -a -b -- test then $@ will be equal to -a -b -- test Note: '--' is used in set command to resolve problems with parameters that begins with '-' character In while loop positional parameters are being processed till '--' ($1 refers to first positional parameter, shift deletes first positional parameter) |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks a lot....
|
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
With KSH you can use getopts : Code:
#!/bin/ksh
while getopts abco: name
do
case $name in
a) a=1;;
b) b=1;;
c) c=1;;
o) o="$OPTARG";;
esac
done
shift $(($OPTIND -1))
# rest of script...
# e.g.
ls -l $@jean-Pierre. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getopt in CSH | animesharma | Shell Programming and Scripting | 4 | 07-26-2011 03:20 AM |
| Help with Getopt::Std | Breakology | Shell Programming and Scripting | 3 | 06-23-2009 09:33 PM |
| getopt help | darshakraut | Shell Programming and Scripting | 3 | 06-20-2008 08:15 AM |
| getopt help | darshakraut | Shell Programming and Scripting | 2 | 06-18-2008 07:43 AM |
| getopt help | problems | Shell Programming and Scripting | 1 | 05-02-2006 04:23 AM |
|
|