'Unable to redirect error to /dev/null in gnu make

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


Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MadScientist