I noticed that this works fine (will print only the PID of unattended-upgrades
process):
lslocks | awk '/unattended-upgrades/ { print $2 }'
But this effectively ignores the print
part (will print the entire line):
bash -c "lslocks | awk '/unattended-upgrades/ { print $2 }'"
This is an Ubuntu 18.04 and Bash version 4.4.20.
What is spacial about bash -c
that causes this?
bash -c
,ssh
, and many others) as in your Q. See Why does my shell script choke on whitespace or other special characters? and be sure to follow the link to the quoting tag. – cas Mar 18 '22 at 03:46