Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I work around MacOS X not having xargs -d?

Tags:

linux

macos

xargs

xargs -d '\n' -n 8 bash -c 'phpcs_element PSR2 "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"' -- >&2 2>/dev/null

If I run this command into Linux it will work, if I try to run in into Mac OSX will not because the OSX xargs doesn't know about xargs -d (delimiter).

xargs: illegal option -- d
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements] [-S replsize]]
             [-J replstr] [-L number] [-n number [-x]] [-P maxprocs]
             [-s size] [utility [argument ...]]

Xargs Version: src/usr.bin/xargs/strnsubst.c,v 1.7 2004/10/18 15:40:47

like image 889
Stefan DOK Avatar asked Jan 24 '26 13:01

Stefan DOK


2 Answers

Just use -0 instead (making the NUL character the delimiter), and convert your newlines to NULs (which are what you ought to be using to separate items in a list of file names in the first place: the NUL, not the newline, is the only character that cannot exist in a filesystem path).

tr '\n' '\0' |
  xargs -0 -n 8 bash -c 'phpcs_element PSR2 "${@:1:8}"' -- >&2 2>/dev/null
like image 126
Charles Duffy Avatar answered Jan 26 '26 05:01

Charles Duffy


If you have Homebrew, you can install findutils with this command:

brew install findutils

Then, you will be able you use -d.

You just have to prepend xargs with a g (making it gxargs).

Reference: https://superuser.com/a/467284/529605

like image 33
Wit Avatar answered Jan 26 '26 06:01

Wit