从 .aliases 重定向 tcsh 中的 STDERR

发布于 2024-07-05 19:22:29 字数 1025 浏览 5 评论 0原文

在 tcsh 中,我试图从 .aliases 文件中的命令重定向 STDERR。

我发现我可以像这样从命令行重定向 STDERR 。 。 。

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

。 。 。 但是当我将其放入 .aliases 文件中时,我得到了一个别名循环。 。 。

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

。 。 。 所以我在 .aliases 中的命令之前添加了一个反斜杠,这允许命令运行。 。 。

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

。 。 。 但现在我不能给命令任何参数:

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

任何人都可以提供任何解决方案吗? 先感谢您!


更新:我仍然很好奇是否可以从 .aliases 重定向 tcsh 中的 STDERR,但正如此处所建议的,我最终得到了一个 shell 脚本:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-07-12 19:22:29

我怀疑在这种情况下,不使用别名是最好的选择 - 尝试使用 shell 脚本:

#!/bin/tcsh

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

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
风和你 2024-07-12 19:22:29

尝试

alias emacs '(\emacs \!* > /dev/tty) >& /dev/null'

“错误放置 () 的”消息来自于 emacs 的输入参数放错位置。 如果别名定义中没有“\!*”,“emacs abc”将变为

(/usr/bin/emacs > /dev/tty) >& /dev/null abc

包含“\!*”的“emacs abc” >emacs abc" 变为

(/usr/bin/emacs abc > /dev/tty) >& /dev/null

Try

alias emacs '(\emacs \!* > /dev/tty) >& /dev/null'

The "badly placed ()'s" message comes from misplacing the input parameter to emacs. Without the "\!*" in the alias definition, "emacs abc" becomes

(/usr/bin/emacs > /dev/tty) >& /dev/null abc

With the "\!*" included, "emacs abc" becomes

(/usr/bin/emacs abc > /dev/tty) >& /dev/null
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文