Bash – Ambiguous output redirect

bashio-redirectionstderrstdout

I'm trying to redirect stderr to stdout and then out to a file in an init script, but when I introduce stderr to stdout I get the “Ambiguous output redirect” error. Stdout alone does not result in the error, and writes to the log file where I stated. I've tried the following

-jar /jbeaulau_test/microservices/config-server-0.0.2-RELEASE.jar &>/jbeaulau_test/microservices/log/all.log &

-jar /jbeaulau_test/microservices/config-server-0.0.2-RELEASE.jar >/jbeaulau_test/microservices/log/all.log 2>&1 &

Any advice would be appreciated.

Best Answer

If you're running (t)csh, you get Ambiguous output redirect. if you try to set up two conflicting redirections:

> echo foo > a > b
Ambiguous output redirect.

In Bash, you could get a similar error if use an array with multiple elements in place of the filename:

$ set aa bb
$ echo foo > "$@"
bash: "$@": ambiguous redirect

As mentioned in answers to stderr redirection not working in csh, the >& operator works in (t)csh to redirect both stdout and stderr. 2>&1 is the standard way to redirect stderr to the same place as stdout, but (t)csh doesn't support that. Instead, it takes the combination > foo 2>&1 as a redirection to foo, a regular argument 2, and a redirection to 1, and the redirections conflict, so you get the error.

>& also works in Bash and zsh, but isn't a standard feature.

Related Question