Home > other >  Unable to redirect error to /dev/null in gnu make
Unable to redirect error to /dev/null in gnu make

Time:05-14

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

CodePudding user response:

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)
  • Related