An employee experimented with truncating a file in a bash shell: extracting the first two bytes from a binary file.
On BSD / OS X ("12" on the output) worked fine, but not on Linux (the output was empty):
echo 1234 >test
head -c2 test | tee test >/dev/null
Change part head | tee
to run in subshell
echo 1234 >test
(head -c2 test | tee test >/dev/null)
made it work with Linux too.
Why?
(In particular, he is not interested in solutions to the truncation problem, but explains why the behavior differs from the different tastes of the operating systems.)
source
share