I have a command that I would execute to generate a random string:
var=`< /dev/urandom tr -dc _A-Zaz-0-9 | head -c8`
When I run this command in an interactive bash session, I get absolutely no errors. But when I put this command in a script and run it as a script, I get a Broken pipe error, indicated by tr. I read several related topics, but still haven't answered why the script and interactive behavior are different, and is there any way to control it with shell options or with something else?
Edit I:
Regarding the comments provided, I found that the indication of faulty pipe errors can be controlled with:
trap - SIGPIPE
and
trap "" SIGPIPE
Edit II:
Well, I provided incorrect information about the playback conditions. Finally, it seems that the problem is with the python shell that called the script using os.system ():
python -c "import os; os.system('sh -c \"< /dev/urandom tr -dc _A-Zaz-0-9 | head -c8\"')"
The above line gives broken pipe errors regardless of the OS used.
Edit III:
This section was discussed here: https://mail.python.org/pipermail/python-dev/2005-September/056341.html
source share