无法将错误重定向到GNU中的 /dev /null
在GNU脚本中,我想检查Intel C编译器是否在路径中。 为此,我运行以下命令:
COMPILER_IN_PATH := $(shell icc -dumpversion | grep 2021.3.0)
稍后我测试以查看是否设置了Compiler_in_path。
如果英特尔编译器在路径中,则上述命令正常工作。 但是,如果Intel编译器不在路径中,尽管上述命令工作(compiler_in_path将无法设置),我在运行此行时在输出中看到以下错误消息:
/bin/sh: icc: command not found
我想摆脱该错误消息。在将Stdout读取Compiler_in_path变量时,如何将stderr重定向(我想 /dev /null)?
这是我的一些失败尝试:
icc -dumpversion | grep 2021 > /dev/null 2>&1
Ambiguous output redirect.
icc -dumpversion | grep 2021 2> /dev/null
icc: Command not found.
grep: 2: No such file or directory
In a gnu script, I want to check if an intel c compiler is in the path.
To do this, I run the following command:
COMPILER_IN_PATH := $(shell icc -dumpversion | grep 2021.3.0)
Later I test to see if COMPILER_IN_PATH is set.
If an intel compiler is in the path, the above command works fine.
However, if an intel compiler is not in the path, though the above command works (COMPILER_IN_PATH will not be set), I see the following error message in the output when this line is run:
/bin/sh: icc: command not found
I would like to get rid of that error message. How do I redirect stderr somewhere (to /dev/null, I suppose) while reading the stdout into the COMPILER_IN_PATH variable ?
Here are some of my failed attempts:
icc -dumpversion | grep 2021 > /dev/null 2>&1
Ambiguous output redirect.
icc -dumpversion | grep 2021 2> /dev/null
icc: Command not found.
grep: 2: No such file or directory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在重定向
grep
命令的输出。您需要重定向icc
命令的输出。You are redirecting the output of the
grep
command. You want to redirect the output of theicc
command.