linux - "&>>" in sh behaves differently in Ubuntu 16.04.2 and Fedora 24 -
consider following sh command:
sh -c 'sleep 3 &>> /dev/null'
&>>
supposed redirect stdout
, stderr
. however, interpreted differently in fedora 24 , ubuntu 16.04.2.
in fedora 24, works in way, , command above waits until sleep
ends.
in ubuntu 16.04.2, command runs sleep 3 & >> /dev/null
, is, sleep
sent background , command exits immediately.
the difference causes weired problems , cannot found since call things foo arg1 arg2 output_file &>> test.log
in r script , expect command ends output_file
written. in fedora 24, works expected surprise behavior changes in ubuntu 16.04.2.
i'm not sure if documented behavior.
sh
notbash
.sh
in fedorabash
, when invokedsh
behaves "closely" the posix standard.sh
in ubuntudash
.&>>
bashism.
the last link explains how fix dash
(the sh
in ubuntu):
sh -c 'sleep 3 > /dev/null 2>&1'
this work in bash. note single >
- don't need use append operator (>>
) /dev/null.
tip: seeing might tempting write scripts compatible both implementations of sh
, you'll make life unnecessarily difficult. use most powerful shell can expect available default on platforms you're interested in. in case bash
(version 4), default on many other distros.
Comments
Post a Comment