I have a script that we use on Ubuntu (Linux) and I'd like to convert it to be used on both Ubuntu (Linux) and MacOS X. grep
on Linux is different than grep
on FreeBSD (i.e. MacOS X); grep
on MacOS X doesn't support the -P
option. Unfortunately, using the -E
option on both platforms doesn't give the same results. Consider the following code that works on Linux:
wip_scenarios=$(grep -oP "^\d+ scenarios?" log/report.log | grep -oP "\d+")
echo "\n"
echo $wip_scenarios
This returns a 0
on Linux. Replacing all the -P
with -E
makes this work on MacOS X, but on Linux, this just returns a null
which doesn't help the rest of my script when I use conditionals like this:
if [ $wip_scenarios != 0 ];then
One solution is to put a flag at the front and use the appropriate option set depending on the platform, but I was hoping for a cross-platform solution. Is there a way to do this?