I'm having trouble understanding what I need to escape when using sh -c
.
Let's say I want to run the for loop for i in {1..4}; do echo $i; done
. By itself, this works fine.
If I pass it to eval
, I need to escape the $
: eval "for i in {1..4}; do echo \$i; done"
, but I cannot make it work for sh -c "[...]"
:
$ sh -c "for i in {1..4}; do echo $i; done"
4
$ sh -c "for i in {1..4}; do echo \$i; done"
{1..4}
$ sh -c "for i in \{1..4\}; do echo \$i; done"
{1..4}
$ sh -c "for i in \{1..4\}\; do echo \$i\; done"
sh: 1: Syntax error: end of file unexpected
Where can I find more information about this?
sh
?which sh
->/bin/sh
;file /bin/sh
->/bin/sh: symbolic link to dash