Am 27.02.2011 21:09, schrieb hamilton:
> On Sun, 27 Feb 2011 21:01:46 +0100, Florian Philipp wrote:
>> Hi list!
>>
>> I'm currently streamlining some of my shell scripts to avoid unnecessary
>> process calls where bash itself is powerful enough.
> 
> My experience (take it for whatever you think it's worth) is that
> doing so often just makes things harder to follow and maintain.
> It's very unlikely that the overhead of a fork+exec is appreciably
> slowing your process down.  Having said that (and in that vein) there
> is something more straightforward which may be useful:
> 

Oh, I completely agree with you. In 90% of all cases, simple and clean
code is preferable. And if I really card about performance, I'd use C or
Perl. However, there are still such rare cases where everything works
fine and you see no reason to code it all again but those three forks in
the innermost loop just kill your performance.

In such cases, I optimize it and put the clean version in the comments.
That way, clarity doesn't suffer too much.

> [...]
> 
>> My current solution is using two string operations:
>> string='foo:bar:foo'
>> # remove everything up to and including first ':'
>> second_and_following=${string#*:}
>> # remove everything from the first ':' following
>> second_field=${second_and_following%%:*}
> 
> second_field = $(echo $string | awk -F: '{print $2}')
> 
> 

Regards,
Florian Philipp

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to