redirect STDERR in tcsh from .aliases

pdiddy picture pdiddy · Sep 25, 2008 · Viewed 7.5k times · Source

in tcsh I'm trying to redirect STDERR from a command from my .aliases file.

I found that I can redirect STDERR from the command line like this. . .

$ (xemacs > /dev/tty) >& /dev/null

. . . but when I put this in my .aliases file I get an alias loop. . .

$ cat .aliases
alias xemacs '(xemacs > /dev/tty ) >& /dev/null'
$ xemacs &
Alias loop.
$

. . . so I put a backslash before the command in .aliases, which allows the command to run. . .

$ cat .aliases
alias xemacs '(\xemacs > /dev/tty ) >& /dev/null'
$ xemacs &
[1] 17295
$ 

. . . but now I can't give the command any arguments:

$ xemacs foo.txt &
Badly placed ()'s.
[1]    Done                          ( \xemacs > /dev/tty ) >& /dev/null
$ 

Can anyone offer any solutions? Thank you in advance!


UPDATE: I'm still curious if it's possible to redirect STDERR in tcsh from .aliases, but as has been suggested here, I ended up with a shell script:

#!/bin/sh
# wrapper script to suppress messages sent to STDERR on launch
# from the command line.
/usr/bin/xemacs "$@" 2>/dev/null

Answer

Dominic Eidson picture Dominic Eidson · Sep 25, 2008

I suspect this is a case where NOT using an alias is the best option - try using a shell script instead:

#!/bin/tcsh

(xemacs $* > /dev/tty ) >& /dev/null