bash expansion help

Steve Harvey sgh-Ja3L+HSX0kI at public.gmane.org
Wed Feb 7 21:11:28 UTC 2007


On Tue, Feb 06, 2007 at 07:42:30PM -0500, William Park wrote:
> On Mon, Feb 05, 2007 at 01:16:54PM -0500, Lennart Sorensen wrote:
> > > Can you find a way do do this with less overhead?  I count two
> > > invocations of the shell, one implicit by using `` and one explicit.
  Oops!  I missed one.  See below.
> > 
> > Hmm, I missed that if was expanding $arm_opts.  I had been playing with
> > it as just foo=`echo ARM{610,710,_{SA110,SA1100,XSCALE}}` which didn't
> > need another shell.  Given the extra variable, no I don't think I can
> > find a shorter method.  Not sure eval or anything else would do it, but
> > it would take more characters to do it for sure.
> 
> I'm sure of it. :-)  Try
>     eval echo ...

  Using eval turns out to be lot more parsimonious.  This can be
verified using strace.

$ arm_opts_exp=`eval echo $arm_opts`  #only a single fork w/o execve
$ arm_opts_exp=`echo echo $arm_opts | bash`   
 
  The second form forks three times; the process that parses the
stuff between the backticks has to, in turn, fork a process
to handle each piece of the pipeline.  To make matters worse from a
performance POV (not that it often matters), the second of these must 
locate and exec the bash executable.  Piping into bash also has the
disadvantage (tried on version 2.05b.0 with libc-2.3.1 which may be 
a wee bit dated) in that it cannot perform a seek on its input to
determine its length, it then reads it one character at a time.

> BashDiff: Super Bash shell
> 	  http://freshmeat.net/projects/bashdiff/

  Ahh!  You forgot the kitchen sink.  :-)
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list