-1

With bash I can run:

$ ssh bashuser@localhost '( ls -d / nosuchfile ) & echo foo; wait'
foo
ls: cannot access nosuchfile: No such file or directory
/

If I try the same with csh I get:

$ ssh cshuser@localhost '( ls -d / nosuchfile ) & echo foo; wait'
[1] 187253
foo
ls: cannot access nosuchfile: No such file or directory
/
[1]    Exit 2                 ( ls -d / nosuchfile )

I would like to get the same output as bash. How do I avoid the [1] PID and [1] Exit ...? Can I somehow put csh in quiet mode?

The ls and echo foo are of course only examples. In reality they will be much more complex and will depend on being run under the login shell and I will need stdout and stderr, so a simple grep -v of the output will not work.

Ole Tange
  • 35,514
  • 1
    I thought this question looked familiar; and you asked a similar question the other day... What are you trying to achieve here? I suspect you're using the wrong solution to sole a problem you haven't described (ie. XY problem). You should describe the problem you're trying to solve... Making code work in both bourne shell and the C shell is impossible, since they're only superficially the same & very different. – Martin Tournoij Jan 17 '15 at 16:48

1 Answers1

0

Doesn't look like you can without some magic trickery (ie. there's no option). You can use sh -c, though:

$ ssh cshuser@localhost 'sh -c "( ls -d / nosuchfile ) & echo foo; wait"'   
foo
ls: nosuchfile: No such file or directory
/

IMHO this is the best option anyway, since there are more shells than bash & csh (such as fish), and you have no guarantee on how any of them behave...

Martin Tournoij
  • 1,715
  • 2
  • 15
  • 35
  • The point about the guarantee is spot on. This is exactly why I cannot use sh -c: There is no guarantee that the command will work in sh. Only the user will know which shell is the correct answer; I will not. – Ole Tange Jan 17 '15 at 16:38
  • @OleTange What? sh is pretty much guaranteed to be on the system. You can't write scripts that behave exactly the same in bourne shell & the C shell, since they're only superficially the same... I don't see how this is not 'guaranteed that the command will work in sh' ... – Martin Tournoij Jan 17 '15 at 16:45