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) andbashare superfluous here.xargs -rd '\n' -n1 log -elog() { echo $1; } ; export -f log ; echo test| xargs -rd '\n' -n1 logxargs -rd '\n' -n1 bash -c 'log "$@"' bash(avoid_for$0). But instead of running onebashper line, you may want to use awhile IFS= read -r lineloop within one bash instance and do away withxargs.