anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.63k stars 130 forks source link

Fix bash -c example, $0 is also specified on the cmdline #40

Closed DanielG closed 3 years ago

DanielG commented 3 years ago

Notice how the following only prints 2 and 3

bash -c 'printf "%s\n" "$@"' 1 2 3
2
3

because 1 is absorbed into $0:

bash -c 'printf "%s\n" "$0" "$@"' 1 2 3
1
2
3
anordal commented 3 years ago

You are right that $0 steals the first argument from $@. But that's why I use $0 and $1 in my example. Are you sure that's not correct?

DanielG commented 3 years ago

Ah, it appears I'm blind. My brain just seems to have ignored the $0, $1 and assumed you'd used $@ it seems :)

I still feel like this is a nasty "feature" of the -c option that should be pointed out.