>" in sh behaves differently on Ubuntu 16.04.2 and Fedora 24 Consider the following sh command: sh -c 'sleep 3 &>> /dev/null' &>>supp...">

"& >>" in sh behaves differently on Ubuntu 16.04.2 and Fedora 24

Consider the following sh command:

sh -c 'sleep 3 &>> /dev/null'

&>>supposed to redirect stdoutand stderr. However, this is interpreted differently in Fedora 24 and Ubuntu 16.04.2.

In Fedora 24, it works that way, and the team above is waiting for completion sleep.

In Ubuntu 16.04.2, a command is launched as sleep 3 & >> /dev/null, that is, sleepsent to the background, and the command immediately terminates.

The difference causes migration problems and cannot be easily found, as I call things like foo arg1 arg2 output_file &>> test.login the R script and expect the command to end with output_file. On Fedora 24, it works as expected, but, to my surprise, behavior changes in Ubuntu 16.04.2.

I am not sure if this is documented behavior.

0
source share
1 answer

The last link explains how to fix it for dash( shon Ubuntu):

sh -c 'sleep 3 > /dev/null 2>&1'

This will also work in Bash. Note the single >- you do not need to use the append ( >>) operator with / dev / null.

. , , sh, . , . bash ( 4), .

+2

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


All Articles