getopts

Using getopts within user-defined-function in bourne shell

Is it possible to pass command line arguments into a function from within a bourne script, in order to allow getopts to process them. The rest of my script is nicely packed into functions, but it's starting to look like I'll have to move the argument processing into the main logic. The following is how it's written now, but it doesn't ...

Using getopts in bash shell script to get long and short command line options

I wish to have long and short forms of command line options invoked using my shell script. I know that getopts can be used, but like in Perl, I have not been able to do the same with shell. Any ideas on how this can be done, so that i can use options like: ./shell.sh --copyfile abc.pl /tmp/ ./shell.sh -c abc.pl /tmp/ In the above, bo...

getopts Values class and Template.Substitute don't (immediately) work together

I have python code something like: from string import Template import optparse def main(): usage = "usage: %prog options outputname" p = optparse.OptionParser(usage) p.add_option('--optiona', '-a', default="") p.add_option('--optionb', '-b', default="") options, arguments = p.parse_args() t = Template('Option a is ${optiona...

Parsing getopts in bash

I've got a bash function that I'm trying to use getopts with and am having some trouble. The function is designed to be called by itself (getch), with an optional -s flag (getch -s), or with an optional string argument afterward (so getch master and getch -s master are both valid). The snippet below is where my problem lies - it is...

Is there a way to have a string as a switch using getopts?

I am seeing if there is a way for getopts to handle switches with strings instead of characters. For example, I would like to supply something like this: script.ksh -file1 file1.txt -file2.txt Instead of: script.ksh -f file1.txt -g file2.txt Is this possible with unix getopts? Thanks! ...

getopts for Windows batch files?

Is there an easy way to detect options/switches passed in to a batch file via the command line? I'm looking for something along the lines of sh's and bash's getopts. ...