Why does this script (with pipefail) exit with nonzero status and how can I fix it?
by DoorDaesh from LinuxQuestions.org on (#5BEZ8)
I enabled pipefail in my script for improved safety, but now there is one line that causes the script to fail, even though it's working as intended.
It's this line setting the value of rand_string:
Code:$ set -o pipefail
$ rand_string=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 12)
$ echo $?
# 141I assume it's either the cat or tr command that's exiting with code 141. Which one is it? Why is it doing that? How can I make it stop?


It's this line setting the value of rand_string:
Code:$ set -o pipefail
$ rand_string=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 12)
$ echo $?
# 141I assume it's either the cat or tr command that's exiting with code 141. Which one is it? Why is it doing that? How can I make it stop?