Get around xargs' lack of -d on macos¶
The problem¶
This is only a problem on MacOS, as xargs
doesn't ship with -d
on it.
Consider:
When trying to run a command on each line, eg. appending _updating
to each
line and printing it
echo '1 1\n2 2\n3 3 3' | xargs -n 1 -I {} echo "{}_updated"
# 1_updated
# 1_updated
# 2_updated
# 2_updated
# 3_updated
# 3_updated
# 3_updated
xargs splits each line based on space.
The Solution¶
Use tr '\n' '\0'
. (reference)