I'm trying to write a wrapper script that removes a command-line flag if it's set, performs an action, and then calls a program without that flag. Here's some psudo-code:
Did the user call the script with -flag?
Yes: Set FLAG = 1 and run binary_app with all the parameters given to this script.
No: Run binary_app with all the parameters given to this script.
Here's one way:
OPTS = "$@"
# now remove -flag from OPTS and run binary_app $OPTS
Now suppose my wrapper script is named wrapper_script.sh. If I run
wrapper_script.sh "path/to/file with spaces.txt" -flag
wrapper_script.sh path/to/file\ with\ spaces.txt -flag
then when the wrapper script runs binary_app $OPTS, the file name with spaces gets split up and binary_app sees the filename parts as different arguments.
Here are some of my requirements:
1) I don't know what arguments binary_app takes but the user does. binary_app may take more arguments in the future.
2) The user must be able to specify -flag to wrapper_script, wrapper_script must get rid of this flag before passing the rest of the arguments on to binary_app, and it must perform other actions when -flag is detected.
3) I cannot change binary_app.
4) Filename parameters to wrapper_script.sh with spaces in them must be supported.
I suppose I could loop through every paramter until I find -flag, delete it, recombine the parameters, and then pass them off to binary_app. It seems like there should be a more elegant way, though.