This does not work because the expansion of a variable in a double-quoted string occurs before the command is called. That is, if I type:
echo "$HOME"
The shell will convert this to:
echo "/home/lars"
Before calling the echo command. Similarly, if you type:
sh -c "F=\"123\"; echo $F"
This translates to:
sh -c "F=\"123\"; echo"
Before invoking the sh command. You can use single quotes to prevent variable expansion, for example:
sh -c 'F="123"; echo $F'
You can also avoid $ with a backslash:
sh -c "F=\"123\"; echo \$F"
larsks
source share