pkgsrc-Users archive

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

Re: pkg_alternatives, Darwin and locale



Louis Guillaume wrote:
>
>
> Joerg Sonnenberger wrote:
>> 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 )

What is awk-ward about this is that awk can do so little and you have to
invoke a new shell for each single line which vastly reduces the
advantage of this solution and might make it even less efficient. Perl
would be an obvious replacement but also overkill as a dependency. This
simplified variant is slightly faster than the previously posted shell
fragment under bash but slower than ksh:

awk '{ "echo " $0 | getline; print }'

It's at best twice as fast as slow-poke sh but slower than a fast shell.

>> 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.

> So how's about something like ...
>
> awk '!/^[ \t]*#/{ print $1,$0 }' $files | while read prog alt ;do
>   [ -x "${prog}" ] && exec ${alt} "${@}"
> done

What exactly is the point of this unless there's a huge amount of
comments? Once you read the output of awk you're back to where you came
from and as mentioned in other mails, reading from a pipe is much slower
than reading from a regular file.

Also you're increasing the amount of data to be read by printing "$1"
which is already the first element of "$0".

-- 
Christian


Home | Main Index | Thread Index | Old Index