xargs with the -d flag, and using substitution, causes an extra "empty" item to be processed -
using -d
flag in xargs specify delimter seems tack newline after lastly value. either way, causes command break when using substitution stick value middle of command (vs more "standard" way of having xargs pass value end of command).
to rephrase, happens when using -d
, -i
flags , sticking values middle of command.
how can prepare this?
example:
# echo "server1 server2 server3 server4"|xargs -r -d" " -i+ echo ssh + "sudo service myservice restart" ssh server1 sudo service myservice restart ssh server2 sudo service myservice restart ssh server3 sudo service myservice restart ssh server4 sudo service myservice restart
note lastly command offset newline. not problem if command ended @ newline, in case not.
i've worked around tacking " null"
end of list pass xargs, , ignoring resulting error. lousy solution, , unsafe in cases.
my workaround:
# echo "server1 server2 server3 server4 null"|xargs -r -d" " -i+ echo ssh + "sudo service myservice restart" ssh server1 sudo service myservice restart ssh server2 sudo service myservice restart ssh server3 sudo service myservice restart ssh server4 sudo service myservice restart ssh null sudo service myservice restart
xargs isn't tacking on newline; it's since newline isn't delimiter anymore, newline already in input taken literally.
if you're using echo
supply input xargs, utilize echo -n
doesn't add together newline. if you're using other echo, investigate how can not add together trailing newline, or remove newline using tr
or sed
or perl
or something.
xargs
No comments:
Post a Comment