for exmaple, using the command
cat foo.txt | xargs -I{} -n 1 -P 1 sh -c "echo {} | echo"
The foo.txt
contains two lines
foo
bar
The above command print nothing.
for exmaple, using the command
cat foo.txt | xargs -I{} -n 1 -P 1 sh -c "echo {} | echo"
The foo.txt
contains two lines
foo
bar
The above command print nothing.
cat foo.txt | xargs -J % -n 1 sh -c "echo % | bar.sh"
Tricky part is that xargs performs implicit subshell invocation. Here sh invoked explicitly and pipe not becomes the part of parent conveyor
If you want to process all the lines of foo.txt you will have to use a loop. Use &
to put the process to background
while read line; do
echo $line | bar.sh &
done < foo.txt
If your input contain spaces temporarily set the internal field separator to the newline
# save the field separator
OLD_IFS=$IFS
# new field separator, the end of line
IFS=$'\n'
for line in $(cat foo.txt) ; do
echo $line | bar.sh &
done
# restore default field separator
IFS=$OLD_IFS