Editing files in place with a tie acting differently on different Unix

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 | teeto 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.)

+3
source share
1 answer

tee , , head tee . ; mini- script, - .

+1

Source: https://habr.com/ru/post/1796263/


All Articles