- The command's output (to stdout and stderr) won't be redirected anywhere.
- The command will be executed in the background.
- The file will be truncated, if redirecting to a file and not using >>.
Are the characters saved worth those effects? I don't think so. Just use this instead: "> file 2>&1". Make sure you get the first redirection right, "&> file 2>&1" isn't going to do the trick.
The space isn’t even needed, so “>file 2>&1” is fine, or “>>file 2>&1”.
ReplyDeleteThe order of these two is important though. If you want to redirect both stdout and stderr, the “2>&1” must come after the stdout redirection, not before. (The mksh manpage has more on this.)
mksh no longer parses the GNU bash “&>” extension when in POSIX or /bin/sh mode because it changes the meaning of previously correct scripts (thanks to the guys in #!/bin/mksh on Freenode IRC for pointing this out):
ReplyDelete1) "$__progname" -c 'echo foo>/dev/null&>/dev/fd/2 echo bar1'
2) "$__progname" -o posix -c 'echo foo>/dev/null&>/dev/fd/2 echo bar2'
expected-stderr:
1) foo echo bar1
2) bar2