On Mon, Jul 21, 2008 at 05:02:08PM -0400, Louis Guillaume wrote:
+found=$(awk '!/^[ ]*#/{
+ f = "if [ -x " $1 " ] ; then echo " $0 " ;fi " | getline found
+ if ( f == 1 ) {
+ print found
+ exit
+ }
+}' $files )
+
Better, but still better is to use a while loop for the outer part.
The problem with "while read foo" in shell is that it will do a system
call per byte. If you can move all the other processing inside awk,
that is preferable. The test builtin is less expensive than the reading
though, so
awk ... | while read prog alternative; do
if [ -x "$prog" ]; then
echo $alternative
break
fi
done
or so is most readable and involves the smallest number of forks.
Joerg