Currently I have a script that does some extra processing, but ultimately calls the command the user passed (FYI, this is to run some commands in a docker container, but we'll call it foo.sh):
#!/usr/bin/env bash
# ...
runner "$@"
This works great (e.g. foo.sh echo HI), until the users wants to pass multiple commands to be run:
e.g.: foo.sh echo HI && echo BYE
&& is of course interpreted by the ambient shell before being passed into arguments.
Is there a workaround or means of escaping && that might work?
runner bash -c "echo HI && echo BYE"execlineis a good source of inspiration to consider, built for graceful use in just the kind of scenario your question anticipates. (To be clear,execlineis not mine, but something I've used as food for thought in building a toolset for related purposes)"$@"could expand to content parsed as syntax, passing untrusted data around in bash would be effectively impossible.