Suppose I have the following process to write a number + single quote to the file /tmp/test
every second:
for i in {1..1000} ; do echo $i\' ; sleep 1 ; done > /tmp/test
I then want to use tail -f
and run this through another function. For testing purposes, I'm using echo
:
tail -f /tmp/test | xargs echo
This give me the following error (running this without a quote in the input works fine):
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
If I add sed to the equation, I don't get any output at all:
tail -f /tmp/test | sed "s/['\"]//g" | xargs echo
Any ideas why I get no output after adding sed
, or another way how I can strip the quotes from the input before it gets to xargs
?
echo
? Each blank-delimited word in the input (quotes not special, how about backslash?)? Or the full content of each line?xargs -0 -n1 -d '\n' -I {} bash -c 'log -e "$@"' _ {}
which seems to be working now after adding the -d parameter-0
,-n1
(or-I
) andbash
are superfluous here.xargs -rd '\n' -n1 log -e
log() { echo $1; } ; export -f log ; echo test| xargs -rd '\n' -n1 log
xargs -rd '\n' -n1 bash -c 'log "$@"' bash
(avoid_
for$0
). But instead of running onebash
per line, you may want to use awhile IFS= read -r line
loop within one bash instance and do away withxargs
.