I have a command:
synclient -l | awk -v param_name=$param_name '$1==param_name {print $(NF)}'
and its output is just: 0
.
But if I replace both '
with "
, I'm getting:
Command 'NF' not found, but can be installed with:
sudo apt install byobu
awk: cmd. line:1: ==param_name {print }
awk: cmd. line:1: ^ syntax error
The same error appears when I use sh -c
on the commands:
sh -c "synclient -l | awk -v param_name=$param_name '$1==param_name {print $(NF)}'"
sh -c 'synclient -l | awk -v param_name=$param_name "$1==param_name {print $(NF)}"'
What's the difference between '
and "
here? Why does it happen?
'$param'
within single quote characters is not expanded, and this happens in both cases in your original question. Use only double quote characters around variables"$param"
.