"找不到命令"消息被重定向过 [英] "command not found" message is redirected too

查看:159
本文介绍了"找不到命令"消息被重定向过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ foobar
sh: foobar: not found
$ foobar 2>/dev/null
$ 

我想重定向只foobar的的标准错误(如果存在foobar的,可以运行),但外壳的错误信息被重定向了。这发生在bash和ksh和sh,而不是在csh。我不熟悉的Bourne shell源$ C ​​$ C,但我想这是因为shell首先叉,然后重定向,然后试图EXEC(),并在执行exec()失败,发送一个错误信息到一个已经标准错误被重定向。

I'm trying to redirect only foobar's stderr (if foobar exists and can be run), but the shell's error message get redirected too. This happens in bash, ksh and sh, but not in csh. I'm not familiar with bourne shell source code, but I guess this happens because the shell first forks, then redirects, then tries exec(), and when exec() fails it sends an error message to stderr that has already been redirected.

推荐答案

如果foobar的是一些可执行文件然后尝试: -

If foobar is some executable then try:-

$ ./foobar
sh: foobar: not found
$ ./foobar 2>/dev/null #alternatively you can use full path.
$ 

这篇关于"找不到命令"消息被重定向过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆