bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: combine xargs with EOF


From: Greg Wooledge
Subject: Re: combine xargs with EOF
Date: Wed, 17 Oct 2012 13:26:34 -0400
User-agent: Mutt/1.4.2.3i

On Wed, Oct 17, 2012 at 09:49:10AM -0700, address@hidden wrote:
> ls *.txt | xargs -n 1 -P 10 bash myscript.sh 

This has some serious flaws already.  ls may mangle the filenames that
it is feeding to xargs.  Any filenames that have spaces or quotes in
them will be bungled by xargs itself.  Any filenames that contain newlines
will most definitely be mishandled.

> where myscript.sh is (for examples of course is longer):
> echo $1

Use more quotes!

> i would like to perform the same operation using the EOF syntax and import 
> the arguments inside the eof
> 
> I tried 
> 
> ls *.txt | xargs -n 1 -P 10 <<
> echo $1
> EOF

You mean a here document.  But it's not clear what you intended.  A here
document is a redirection of stdin.  But xargs's stdin is already coming
from the pipeline.  (Also you forgot the EOF sentinel after <<.)

> also with the option -E and -e but did not work 

Presumably you mean the -E option of xargs, which is "-E eof-str ...
Set the end of file string to eof-str.  If the end of file string occurs
as a line of input, the rest of the input is ignored."

You seem to be conflating this with bash's here documents somehow.
xargs's -E is just an emergency "abort!" button, to stop processing input
at a certain point.

But... I am still having trouble guessing what result you want.
Was the purpose of the here document simply to avoid having a second
file containing a bash script?  If so, then what you probably wanted
was something like:

find . -maxdepth 1 -name '*.txt' -print0 |
  xargs -0 -n 1 -P 10 bash -c '
    echo "$1"
  '

Note that there are several GNU extensions in this example (on both find
and xargs).  There is no POSIX equivalent to xargs -P, so this whole
approach is non-portable in the first place.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]