This is all a bit messy in my head, so I shall do my best to explain!
I have the following script:
#!/usr/bin/env bash
# make, then run
make --quiet
execute_and_echo() { echo "\$ $@" ; "$@" ; }
# add sudo if we need to - and pass all arguments to the target
if [[ $EUID -ne 0 ]]; then
execute_and_echo sudo ./utility "$@"
else
execute_and_echo ./utility "$@"
fi
The intended purpose is to build the utility using make, then run it (appending sudo if we're not root) while passing all of the arguments that are passed to the script on to the utility. This mostly works, but not with some command line arguments.
One argument that utility accepts is (in a case of extreme recursion) another shell command to run from within the utility. Believe me - this makes sense for my application. The form of that argument might be:
utility -s "echo banana"
This works fine when I run it directly from the command line. However, if I instead run
./run -s "echo banana"
the quotes are stripped out and I get undesired behaviour. Does anyone know how to tweak this to get a better behaved script?