public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Florian Philipp <lists@binarywings.net>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Re: OT: cut replacement with bash builtins
Date: Sun, 27 Feb 2011 22:50:35 +0100	[thread overview]
Message-ID: <4D6AC72B.4040801@binarywings.net> (raw)
In-Reply-To: <4d8ebcfffb7efb9fb1685df5092a61e4@mail.nethamilton.net>

[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

  reply	other threads:[~2011-02-27 21:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27 20:01 [gentoo-user] OT: cut replacement with bash builtins Florian Philipp
2011-02-27 20:09 ` [gentoo-user] " hamilton
2011-02-27 21:50   ` Florian Philipp [this message]
2011-02-27 21:06 ` [gentoo-user] " Alex Schuster
2011-02-27 22:08   ` Florian Philipp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D6AC72B.4040801@binarywings.net \
    --to=lists@binarywings.net \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox