The bash manpage states the following for the -c
option:
-c If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.
From the above I would expect the code below to be equivalent in its output:
# or possibly (`bash -c date date +%z`)
$ bash -c date +%z
Wed Oct 18 10:02:47 PM UTC 2023
$ date +%z
+0000
# The first command gives the output of `date` without the format specifier.
However, my bash (GNU bash, version 5.2.15) never seems to evaluate additional command line positional parameters. Everything after the first argument after the -c
option is silently discarded. Perhaps I am misunderstanding the man page.
How would I pass multiple arguments to a bash -c
command as words (arg vector under the hood) rather than one string (bash -c "date +%z"
)? Is this possible?
Context
My goal in asking this question is to understand how bash expects command parameters to be passed in order to correctly feed them into bash via one of the execve()
family of functions from another program (a wrapper shell).