I am trying to understand how error catching works when piped to awk
in a bash script. I have a bash script with :
#!/bin/bash
set -e
echo "hello"
OUTPUT=`ls /root/* | awk '{print $0}'`
echo "world"
When I run this as a non-privileged user, the output is
hello
ls: cannot access /root/*: Permission denied
world
despite the fact that set -e
should cause my script to end if any error occurs. The line echo "world"
should not be executed because the script does generate an error.
Now if I replace the awk
statement with grep poo
, the script exits as expected.
QUESTION: What is awk
doing that manages to hide the errors from bash?