![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help in getopts | chella | Shell Programming and Scripting | 4 | 11-01-2007 10:09 PM |
| precedence of stderr and stdout | new2ss | Shell Programming and Scripting | 1 | 06-08-2006 08:03 PM |
| help in getopts | problems | Shell Programming and Scripting | 1 | 05-04-2006 08:07 PM |
| getopts | yerra | Shell Programming and Scripting | 5 | 03-26-2005 07:43 AM |
| EOF & precedence of != | alan | High Level Programming | 4 | 04-29-2004 11:47 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
setting precedence with getopts
Hi,
I am re-writing a script I wrote which emulated the "rm" command, in my orginal script I had problems with precedence, I did find a way round it by creating a seperate case statements which checked the options and performed the actions accordingly, does anyone know if I can use getopts better to help with precedence? and save on using the extra case statement. So instead of this part of my code: Code:
function delete() {
while :
do case $OPTS in
v|ivf|vf|ifv|vif) verbose $@
break
;;
fi|vfi|fvi|iv|vi|fiv) intVerbose $@
break
;;
f|fv|if) mv -f $@ $TRASH 2>/dev/null
break
;;
i) int $@
break
;;
r)mv $@ $TRASH 2>/dev/null
break
;;
*)mv $@ $TRASH 2>/dev/null
break
esac
done
}
# GETOPTS
while getopts :rRfvi o
do case $o in
r|R) FLAG_R=
;;
f) FLAG_F=f
;;
v) FLAG_V=v
;;
i) FLAG_I=i
;;
*) errorInvalidOpt
esac
done
shift `expr $OPTIND - 1`
OPTS=$FLAG_R$FLAG_F$FLAG_I$FLAG_V
Code:
while getopts :rRfvi o
do case $o in
r|R) FLAG_R=r #what can I add to my getopts to set the right flags
;; # in order with rm's precedence
f) FLAG_F=f
;;
v) FLAG_V=v
;;
i) FLAG_I=i
;;
*) errorInvalidOpt
esac
done
shift `expr $OPTIND - 1`
So, given this option argument: -fi it should not force but should interact but if I enter -if it should not interact but should force, how do I utilise getopts to allow for this withour the case statement in the top code? Thanks Jack |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
You can do somthiong like this :
Code:
while getopts :rRfvi o
do case $o in
r|R) FLAG_R=r #what can I add to my getopts to set the right flags
;; # in order with rm's precedence
f) FLAG_F=f
FLAG_I=
;;
v) FLAG_V=v
;;
i) FLAG_I=i
FLAG_F=
;;
*) errorInvalidOpt
esac
done
shift `expr $OPTIND - 1`
|
||||
| Google The UNIX and Linux Forums |