On 3/11/2012 2:30 PM, Aaron Davies wrote:
> i'm running into an odd problem at work
>
> i have one ksh (93u) script that is effectively a driver for another script 
> (also ksh 93u)
>
> it runs "find" on a directory, and invokes the other script for each file
>
> in order to be slightly better at handling odd filenames, i'm trying to use 
> "find ..|while read" instead of "for f in `find ..`", but the loop is 
> terminating after only one iteration. if i replace the invocation of the 
> shell script with the commands it contains, the loop works as expected. if i 
> use "for", it works as expected
>
> (i need to do a little processing on the names before handing them off to the 
> script (which i don't fully control), so it would be much harder to do with 
> xargs)
>
> i don't have -e or -o pipefail turned on, and in any case, the script is 
> verified to be exiting successfully
>
> any ideas what's going on? i can post an example in a day or two if necessary

This sounds as if the script is reading from stdin. The first line of
the output of find is consumed by the "read", all the rest of the output
of find is consumed by the script, and then there is nothing left for
the next "read". Perhaps replacing "find ... | while read f ; do ...
done" with "find ... | while  read f ; do { ... ; } < /dev/null ; done"
will solve the issue?

You should also look at using "find .... -exec scriptname {} +" (note
the "+" rather than the more well known "\;" at the end of the command),
and in the script use "for f ; do ... ; done", if the script can
tolerate being invoked more than once if there are a lot of filenames.
This is implied by you saying you are not using xargs because you need
to manipulate the names.


_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to