Replacement for xargs -d in osx
Alternatively, you can always install GNU xargs
through Homebrew and the GNU findutils
package.
Install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Follow the instructions. Then install findutils:
brew install findutils
This will give you GNU xargs
as gxargs
, and you can use the syntax you're accustomed to from GNU/Linux. The same goes for other basic commands found in the findutils package such as gfind
or glocate
or gupdatedb
, which have different BSD counterparts on OS X.
How about:
echo {1..4} | xargs -n1 -I{} ssh root@www{}.example.com hostname
From man xargs
:
-n number
Set the maximum number of arguments taken from standard input for each invocation of utility.
You can also use tr
in OSX to convert the commas to new lines and use xargs to enumerate through each item as follows:
echo -n 1,2,3,4 | tr -s ',' '\n' | xargs -I{} ssh root@www{}.example.com hostname