Skip to main content

Ambiguous redirect when running command via ssh [Resolved]

I'm trying to start a program in the background on a remote server via ssh, but this program must be run from the directory it is contained within.

I tried doing the following

ssh -q user@server 'cd directory && command > /dev/null 2>&1 &'

But this results in the error

Ambiguous output redirect.

I am redirecting the output to /dev/null because otherwise the ssh call would not finish.

I have tried wrapping the command in {} and (), as well as with and without quotes but get the same error.

How can I work around this issue?

Question Credit: Flau
Question Reference
Asked July 21, 2019
Posted Under: Unix Linux
1 Answers

As mentioned in comments, the remote user's login shell is csh or tcsh. These shells have very different syntax to the various POSIX shells, and in particular, the syntax for redirections is different.

To redirect both standard output and standard error to /dev/null with these shells, use >& /dev/null:

ssh -q user@server 'cd directory && command >& /dev/null &'

Alternatively, explicitly invoke a POSIX shell to run the command:

ssh -q user@server 'sh -c "cd directory && command >/dev/null 2>&1" &'

credit: Kusalananda
Answered July 21, 2019
Your Answer