I'd like to know the best way of using positional parameters when using the command bash -c
.
The man pages indicates for the -c
option that:
If there are arguments after the command_string, they are assigned to the positional parameters, starting with $0.
So I guess that the following form is the right one:
$ bash -c 'printf "%s %s %s\n" $0 $1 $2' param1 param2 param3
param1 param2 param3
However I saw the following form, and I wonder why it would be better
$ bash -c 'printf "%s %s %s\n" $1 $2' _ param1 param2
param1 param2
In this case, the character _
replaces $0
.
I know that for many interpreters $0
has a special meaning (command name, all positional parameters...), but in this case the man pages are quite clear.
So, is there something wrong with the first form and is there any drawback of using $0
as the first positional parameter for the bash -c
command?