0

Does anyone know why the output of the first snippet is bash instead of test?

$ bash -c "echo $0 $1" "test"
bash
$ bash -c 'echo $0' "test"
test

How can I use bash -c with double quotes and positional parameters $1, $2, etc. ?

user2279952
  • 341
  • 1
  • 4
  • 9
  • `bash -c "echo \$0" "test"` – 0stone0 Jun 16 '21 at 23:11
  • Your use-case is unclear (to me). What output do you expect from the first command? (Please edit your Q rather than reply in comments). As 0stone0 indicates, it's all a matter of obeying the rules of quoting. Setting $1 doesn't happen in your first sample, it is already set, when the parent rocess gets started. Good luck. – shellter Jun 16 '21 at 23:14

0 Answers0