I'm trying to follow this question/answer from Server Fault: In tail -f, how do I filter out stuff that has certain keywords?
The following is producing egrep: empty (sub)expression:
# Respect user's preferred flags, but filter the stuff we explicitly test
# Retain allowed flags in ADD_CXXFLAGS
if [ ! -z "CXXFLAGS" ]; then
ADD_CXXFLAGS=$(echo "$CXXFLAGS" | egrep -v '(\-DDEBUG|\-DNDEBUG|\-O[0-9]|\-Os|\-Og|)')
else
ADD_CXXFLAGS=
fi
echo "User CXXFLAGS: $CXXFLAGS"
echo "Retained CXXFLAGS: $ADD_CXXFLAGS"
Google was not very helpful in providing me suggestions: "egrep: empty (sub)expression". Half of them looked Chinese (literally).
I've tried the simple stuff I know, like replacing single quote with double quote, escaping and not escaping the dash, and similar beginner stuff.
I'm on OS X, which is usually a flavor of the BDSs. But this might be some non-standard Apple behavior.
What's wrong with the expression or sub-expression?
Later, the script uses it like follows. For example, we want to remove -DDEBUG and -DNDEBUG, but retain -maes, -mrdrnd and -mrdseed. Hence the reason we want to filter out some flags, but not other.
# Test Debug build, -O2
export CXXFLAGS="-DDEBUG -g2 -O2 $ADD_CXXFLAGS"
make...
# Test Release build, -O2
export CXXFLAGS="-DNDEBUG -g2 -O2 $ADD_CXXFLAGS"
make...
# Test Debug build, -O3
export CXXFLAGS="-DDEBUG -g2 -O3 $ADD_CXXFLAGS"
make...
# Test Release build, -O3
export CXXFLAGS="-DNDEBUG -g2 -O3 $ADD_CXXFLAGS"
make...
...