Skip to main content
3 of 3
Added additional info
user avatar
user avatar

Solaris grep and regular expressions?

We are trying to find a way to craft a GNUmakefile that works on nearly all Unix compatibles. We were using egrep but it failed on MinGW. We switched to grep -E because it is Posix, but testing shows it is failing on Solaris 11.

A typical usage in the makefile is:

GREP ?= grep
...

IS_X86 := $(shell uname -m | $(GREP) -v "x86_64" | $(GREP) -i -c -E "i.86|x86|i86")
IS_X64 := $(shell uname -m | $(GREP) -i -c -E "(_64|d64)")

The result is:

grep: illegal option -- E
Usage: grep [-c|-l|-q] -bhinsvw pattern file . . .
grep: illegal option -- E
Usage: grep [-c|-l|-q] -bhinsvw pattern file . . .
...

I don't see where -E and -F are optional in Posix (perhaps I missed it). I found Difference between Solaris and POSIX on Stack Overflow, but it states, "Solaris has a full set of POSIX interfaces ...".

Why is Solaris' grep failing to consume -E? Is there a way to engage regular expression support on Solaris besides switching to egrep?


I just setup a fresh test account on the Solaris 11.3 machine to ensure I did not taint the environment.

The account was added with:

# useradd -d /export/home/test -m -s /bin/ksh -c "Testing Accoung" test

80 blocks

Inspecting PATH after logging in:

test@solaris:~$ echo $PATH
/usr/bin:/usr/sbin
user56041