无法将错误重定向到GNU中的 /dev /null

发布于 2025-01-27 18:21:16 字数 642 浏览 1 评论 0原文

在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 技术交流群。

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

发布评论

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

评论(1

埋情葬爱 2025-02-03 18:21:16

您正在重定向grep命令的输出。您需要重定向icc命令的输出。

COMPILER_IN_PATH := $(shell icc -dumpversion 2>/dev/null | grep 2021.3.0)

You are redirecting the output of the grep command. You want to redirect the output of the icc command.

COMPILER_IN_PATH := $(shell icc -dumpversion 2>/dev/null | grep 2021.3.0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文