how to pass string comand to shell pipe to execute it (output of awk)
By Michael Henderson •
For example this works:
echo 1 // output: 1This doesn't work:
'echo 1' | "/bin/sh" // output: echo 1: command not foundWhy string because i have output of awk and i need to pass the string to execute some command like this:
awk '{ print 'chmod 755 "$0"' | "/bin/sh"}' file.txtI need to use string like that because i guess it let me put the parameter where i want in the command.
So i first wanted try it execute manually from bash to see if it works before i put it in the awk print command.
31 Answer
You are passing a string to the shell - however the string you are passing is 1
To pass echo 1 you need something like
echo 'echo 1' | /bin/shor
printf '%s' 'echo 1' | /bin/sh(outside of awk, you don't need to quote /bin/sh).