This is a list of discrepencies I came across while trying to while cross-system compatible makefiles and Bash scripts.
-i
(in-place editing) can work without an argument with GNU sed, but won't work
without an argument on BSD sed and on Busybox.
On BSD sed and Busybox sed, you have to give an argument that corresponds to the suffix added to the file name when the back up file is created. The following works on BSD, GNU, and Busybox sed:
Alternatively, you can use perl
:
-E
doesn't work with BSD sed but works on Busybox and GNU sed. Because of this,
|
, +
, \s
, ?
, and \t
don't work, as explained in the article
BSD sed vs. GNU sed. For example,
produces:
Instead you can use:
-i
(in-place editing) only works [1] with recent versions of GNU awk (4.1.0 and above). On BSD, the only solution is to use a temporary file:
-I'{}'
: BSD xargs only replaces the 5 first arguments. For example,
produces:
The flag --max-procs
is only available on GNU xargs and BSD xargs but
not on Busybox xargs. Instead, you can use -P
.
-v
(adjust value) only works on BSD date. The equivalent on GNU date is -d
but with a slightly different way of giving the duration. On busybox, this flag doesn't exist.
BSD | GNU | Busybox |
---|---|---|
date -v+12H |
date -d+12hours |
not available |
Thu Oct 13 20:43:03 CEST 2022 |
Thu Oct 13 08:44:52 PM CEST 2022 |
n/a |
NOTE: On macOS find and GNU find,
-d
stands for "depth-first", to not be confused with-maxdepth
which is compatible with macOS and GNU. Using-d
instead of-maxdepth
will result in the following message:
On macOS, -printf "%P\n"
won't work. On GNU find, %P
displays the relative path instead of
the absolute path whe find
is being run with a different folder than the current folder.
Workaround:
It's tricky, and it all depends on what pattern you are using in -printf
. Regarding %P
, you can replace it with:
Read more about how to substitute -printf
for macOS find: https://stackoverflow.com/questions/752818/find-lacks-the-option-printf-now-what.
uuidgen
(macOS) vs. uuidgen
(GNU)On Ubuntu, uuidgen
belongs to the uuid-runtime
package. The UUIDs are printed in lower case, e.g.
On macOS, the UUIDs are printed in upper case: