I am writing a Makefile which is supposed to work on Linux and on MacOS systems. I make use of the sed
program.
It turns out that BSD sed and gnu sed differ in a small but crucial detail. I cite from the man pages:
BSD:
-i extension ...
GNU:
-i[SUFFIX], --in-place[=SUFFIX]
So on the Mac I have to call
sed -i '' -e 's/foo/bar/' file.tmp
where the empty string after -i
is necesary, while on the Linux machine I call
sed -i 's/foo/bar/' file.tmp
Here is the question:
Is there a safe way to distinguish between the two OS's in the Makefile?
I can of course have the user call Makefile.mac
or Makefile.linux
, but I would rather avoid this.
sed
command? Run something likesed -i ext 's///' <<<input
and see if it succeeds or errors? That should succeed with bsd sed and fail on GNU sed I believe. – Etan Reisner