Why does this script (with pipefail) exit with nonzero status and how can I fix it?
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 |
141 means 141-128=13=SIGPIPE Broken pipe: write to pipe with no readers.
This is how I would do it: Code:
od -An -N6 -x /dev/urandom | tr -d ' ' Code:
od -An -N6 -tx8 /dev/urandom | tail -c13 Code:
hexdump -n6 -e'"%0x"' /dev/urandom Code:
xxd -l6 -p /dev/urandom |
Does SIGPIPE occur because cat is still "printing" even after head takes what it needs?
|
Yes, see this question.
|
Thanks for the solution. The od command is new to me, so I had to read up on it. I think I understand the purpose of most of those options now.
Could you explain the purpose of -v? The manual says: Code:
-v, --output-duplicates |
Yep. I amended my post and removed -v: it's not required here, as there's only one line of output anyway.
Also, see detailed explanation of pipefail behavior in BashPitfall #60. |
All times are GMT -5. The time now is 04:36 AM. |