csh:分叉時擺脫作業+PID

csh:分叉時擺脫作業+PID

使用 bash 我可以運行:

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

如果我嘗試使用 csh 進行同樣的操作,我會得到:

$ 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 )

我想得到與 bash 相同的輸出。如何避免[1] PID[1] Exit ...?我可以以某種方式進入csh安靜模式嗎?

ls當然echo foo只是範例。實際上,它們會更加複雜,並且取決於在登入 shell 下運行,我將需要 stdout 和 stderr,因此簡單的grep -v輸出將無法運作。

答案1

看起來如果沒有一些魔術就無法做到(即沒有選擇)。不過,您可以使用sh -c

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

bash恕我直言,無論如何,這是最好的選擇,因為 shell 比&更多csh(例如fish),您無法保證它們中的任何一個的行為...

相關內容