Note that &>
is a redirection operator that is specific to bash
. You seem to use sh
to execute scripts from the command line (not relying on the #!
-line in the script itself). If you did that to a script that uses &>
, it is definitely not guaranteed to work as /bin/sh
may not be bash
.
Instead, for a portable way of redirecting both standard output and standard error, use
./myscript.sh >output.txt 2>&1
Or, if you do want to use the &>
redirection (and/or other bash
-specific things), use bash scriptname
to execute the bash
script, or make sure that the script has a proper #!
-line pointing to the bash
executable, is executable, and then run the script as ./scriptname
.
In a non-bash
shell, utility &>file
would be the same as
utility & >file
which is the same as
utility &
>file
which would start utility
in the background, and then create an empty file called file
(or truncate file
if it already existed). There is no error in that command, it just doesn't do what a bash
user might expect.