wrapper script using getopts to pass all arguments except one
I have a wrapper script which need to execute the base script, when there is no lock, by accepting all arguments except the -F option. I got so far as below, but not sure how I can ignore the -F switch.
Code:
FILENAME=/somedir/test.sh Any suggestions if this is feasible and how we can go about it? I was thinking of adding an argument count and then go through each argument and skip -F. But I am not sure that is the best/efficient way. Hoping there is a better way. Thanks much |
I would take the complete option string which is passed to the wrapper script. Then replace "-F" by a space. Then pass the result to your original script.
In case that you need to know whether "-F" was included in the original call you can search for that occurrence in the option string. Since you don't have to inspect each option and act upon it, this might be feasible. Unless of course in the call can be a string which also holds "-F" like "MY-FILE". Then you could search for <space>-F<space>. If that all is not feasible you can't avoid actually parsing all options. When you don't parse you don't know what is an option and what not. Check for Bash string functions if you can use the search/replace option. If not and you have to parse, I found this script very helpful: http://code.google.com/p/shflags/ jlinkels |
All times are GMT -5. The time now is 12:36 AM. |