I've tried to handle --options in the long gnu style format using the builtin getopts but it doesn't like it.
I know the external getopt does have an -l switch for this but the external is deprecated and I'd rather avoid using it.
I'm creating a wrapper script. What I need it to be able to take any number of arguments and then if a certain switch or two is passed, to tell the user off and exit 1. But I want everything to pass through to the program if one of the dangerous switches wasn't passed. So it needs to be able to not croak when a user passes --help to the underlying program.
Any ideas?
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Bash: how to handle --options?
- Humbletech99
- Posts: 365
- Joined: 2005-12-29 00:03
On mod's request, I'll rephrase more nicely :Yes, that link is extremely relevant for shell scripting...
The link provided is for C programming and not really relevant to shell scripting. The way I would do it is in a post below.
Last edited by ajdlinux on 2006-09-04 07:04, edited 1 time in total.
BTW, here's an example of processing this in Python:
Haven't tried this code yet but it should work.
Code: Select all
#!/usr/bin/python
import sys, string, os
dangerous_opts = string.find(sys.argv," --dangerous-option") or string.find(sys.argv,"-rf")
if not dangerous_opts:
os.system("my_program "+sys.argv[1:])
- Humbletech99
- Posts: 365
- Joined: 2005-12-29 00:03
well, because what I'm doing is simple I've just parsed it myself, it's smaller and faster than python. Since this is just a wrapper, it needed to just disallow a couple of switches which is easier done just testing them quickly and bailing with an appropriate warning if found.
otherwise python would have been my next stop.
I'm sure that there is another way of doing this in shell, it's just that most people never get deep enough into it, I'll still keep an eye out for a better way to fully parse --long-options the way OptParse does for python.
otherwise python would have been my next stop.
I'm sure that there is another way of doing this in shell, it's just that most people never get deep enough into it, I'll still keep an eye out for a better way to fully parse --long-options the way OptParse does for python.
The Human Equation:
value(geeks) > value(mundanes)
value(geeks) > value(mundanes)