Allen BrownTue Mar 15 16:01:26 PST 2005
Bob Miller wrote: > Allen Brown wrote: > > >>Actually, that doesn't work. >> cdlast foo bar/foobar >>tries to go to ".". > > > It works on my box, GNU bash v2.05b.0(1)-release. > > kbob at jogger-egg kbob $ function cdlast { cd "`dirname \"$_\"`"; } > kbob at jogger-egg kbob $ mkdir -p foo bar/foobar > kbob at jogger-egg kbob $ cdlast > kbob at jogger-egg bar $ pwd > /home/kbob/bar > kbob at jogger-egg bar $ cd > kbob at jogger-egg kbob $ mkdir -p 'foo bar/foobar' > kbob at jogger-egg kbob $ cdlast > kbob at jogger-egg foo bar $ pwd > /home/kbob/foo bar Interesting. But this suggests a non-portability. I'm running the same version of bash. $ bash --version GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu) Copyright (C) 2002 Free Software Foundation, Inc. >>In general I prefer to use $() syntax rather than the older `` >>syntax. > > > I prefer to use the `` syntax because it's portable to BSD, Solaris, > and Irix, among others. $() is a GNUism and doesn't travel. Actually I think bash learned $() from ksh. Isn't ksh older than bash? It works with ksh on HPUX. HPUX is definitely not derived from GNU. I don't have access to those other systems you mention. But aren't you really talking about sh vs ksh/bash? I don't think it is a function of the OS so much as the particular shell. If you compile bash on those other systems, don't you get $()? So I think it does travel. Just not to the original Bourne shell. And the advantage of readability and recursion seem rather compelling to me. Not to mention that if you do much editing of variables using ksh/bash is much much faster than sh because it doesn't require forking to echo and sed for each edit. Yes, I left sh behind years ago. -- Allen Brown work: Agilent Technologies non-work: http://www.peak.org/~abrown/ allen_brown at agilent.com abrown at peak.org Q: What is the opposite of Artificial Intelligence? A: Natural Stupidity.