Execute Remaining Arguments as Command Execute Remaining Arguments as Command shell shell

Execute Remaining Arguments as Command


You don't need an eval here. The “direct” way just works fine:

#!/bin/sh -eufor arg in "$@"do    shift    if [ "$arg" = '--' ]    then        break    fi    echo "Doing something else with argument '$arg'..."done# Execute the remainder as shell command."$@"

Saved as demo.sh:

$ ./demo.sh Foo Bar -- printf '%s\n' "Done 'Foo' and 'Bar'"
Doing something else with argument 'Foo'...Doing something else with argument 'Bar'...Done 'Foo' and 'Bar'

Since the string is expanded only once, the original tokenization stays intact.

If all you want to do is executing a command after another command completed successfully, you could also use

$ ./demo.sh Foo Bar && printf '%s\n' "Done 'Foo' and 'Bar'"

without altering the script itself.