When I run the following script:
#!/bin/bash
cat /dev/urandom | tr -dc '[:graph:]' | head -c 64
(which is supposed to print 64 random characters and it does)
I get the following output:
Kn5Thh'H]F2NMG3^2(T*GdH]C+|Y0uj%C?LGFo=9d9o%vcP9k~6u~Q&exr`RuQv{./myScript: line 2: 21677 Broken Pipe cat /dev/urandom
21678 | tr -dc '[:graph:]'
21679 Done | head -c 64
Why am I getting the Broken Pipe
error? Is it because cat
doesn't finish printing but head
is already done, so it sends a SIGPIPE
?
How do I avoid this?