Skip to main content
-- is not what it seems
Source Link
Matt
  • 9.4k
  • 2
  • 29
  • 33

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c afterincluding a dummy argument for --$0.

bash -c 'printf "[%s] [%s]\n" "$@"' this-is- "$@"
$ ./script one "t w o"
[one] [t w o]

Note without the --, bash -c takes the first argument as $0.

bash -c 'printf "[%s] [%s]\n" "$@"'dollar-zero "$@"
$ ./script one "t w o"
[one] [t w o] []

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c after a --.

bash -c 'printf "[%s] [%s]\n" "$@"' -- "$@"
$ ./script one "t w o"
[one] [t w o]

Note without the --, bash -c takes the first argument as $0.

bash -c 'printf "[%s] [%s]\n" "$@"' "$@"
$ ./script one "t w o"
[t w o] []

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c including a dummy argument for $0.

bash -c 'printf "[%s] [%s]\n" "$@"' this-is-bash-dollar-zero "$@"
$ ./script one "t w o"
[one] [t w o]
add link from muru
Source Link
Matt
  • 9.4k
  • 2
  • 29
  • 33

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c after a --.

bash -c 'printf "[%s] [%s]\n" "$@"' -- "$@"
$ ./script one "t w o"
[one] [t w o]

Note without the --, bash -c gobbles up the first argumenttakes the first argument as $0.

bash -c 'printf "[%s] [%s]\n" "$@"' "$@"
$ ./script one "t w o"
[t w o] []

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c after a --.

bash -c 'printf "[%s] [%s]\n" "$@"' -- "$@"
$ ./script one "t w o"
[one] [t w o]

Note without the --, bash -c gobbles up the first argument.

bash -c 'printf "[%s] [%s]\n" "$@"' "$@"
$ ./script one "t w o"
[t w o] []

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c after a --.

bash -c 'printf "[%s] [%s]\n" "$@"' -- "$@"
$ ./script one "t w o"
[one] [t w o]

Note without the --, bash -c takes the first argument as $0.

bash -c 'printf "[%s] [%s]\n" "$@"' "$@"
$ ./script one "t w o"
[t w o] []
Source Link
Matt
  • 9.4k
  • 2
  • 29
  • 33

To avoid escaping, use "$@" as normal and pass "$@" to the parent bash -c after a --.

bash -c 'printf "[%s] [%s]\n" "$@"' -- "$@"
$ ./script one "t w o"
[one] [t w o]

Note without the --, bash -c gobbles up the first argument.

bash -c 'printf "[%s] [%s]\n" "$@"' "$@"
$ ./script one "t w o"
[t w o] []