euglug.org

[작성자:] admin

  • [Eug-lug] stupid bash question



    Jacob MeuserTue Mar 15 20:16:40 PST 2005

    On Tue, Mar 15, 2005 at 05:18:51PM -0800, Hal Pomeranz wrote:
    > > 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.  
    > 
    > Generally I agree with Allen here.  The one thing I will say is that
    > if you stick with pure Bourne shell syntax then your #!/bin/sh scripts
    > will work no matter what Unix you take them to without any editing.
    > If you go with bash/ksh syntax you'll at least spend some time figuring
    > out where bash/ksh live on each new platform you go to.  Not a huge
    > deal, but a minor annoyance.
    
    to me, it is a major annoyance when people write bash scripts that
    start with !#/bin/sh.  it's OK to use bash extensions, just be sure
    to mark scripts as such.
    
    -- 
    <jakemsr at jakemsr.com>
    
  • [Eug-lug] stupid bash question



    Bob MillerTue Mar 15 17:27:54 PST 2005

    Allen Brown wrote:
    
    > Interesting.  But this suggests a non-portability.  I'm running
    > the same version of bash.
    
    What does it do on your system?
    
    -- 
    Bob Miller                              K<bob>
    kbobsoft software consulting
    http://kbobsoft.com                     kbob at jogger-egg.com
    
  • [Eug-lug] stupid bash question



    Hal PomeranzTue Mar 15 17:18:51 PST 2005

    > 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.  
    
    Generally I agree with Allen here.  The one thing I will say is that
    if you stick with pure Bourne shell syntax then your #!/bin/sh scripts
    will work no matter what Unix you take them to without any editing.
    If you go with bash/ksh syntax you'll at least spend some time figuring
    out where bash/ksh live on each new platform you go to.  Not a huge
    deal, but a minor annoyance.
    
    > 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.
    
    C'mon, it's a shell script.  Are you really that excited about
    performance in most cases?
    
    > Yes, I left sh behind years ago.
    
    I still find myself writing a lot of sh/awk/sed scripts for older
    platforms and also for boot scripts where /sbin/sh may be all you have
    available to you.  Unless there's a piece of ksh/bash syntax I can't
    do without for the script in question, my default is to write pure sh
    code, but then I'm maybe a dinosaur.
    
    -- 
    Hal Pomeranz, Founder/CEO      Deer Run Associates      hal at deer-run.com
        Network Connectivity and Security, Systems Management, Training
    
  • [Eug-lug] stupid bash question



    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.
    
  • [Eug-lug] stupid bash question



    Bob MillerTue Mar 15 15:33:51 PST 2005

    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
    
    > 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.
    
    -- 
    Bob Miller                              K<bob>
    kbobsoft software consulting
    http://kbobsoft.com                     kbob at jogger-egg.com
    
  • [Eug-lug] stupid bash question



    Allen BrownTue Mar 15 11:03:23 PST 2005

    Sorry, I said that wrong.  What doesn't work is
       ls foo bar/foobar
       cdlast
    and it does with the function I present below.
    -- 
    Allen Brown
       work: Agilent Technologies      non-work: http://www.peak.org/~abrown/
             allen_brown at agilent.com	            abrown at peak.org
       Any sufficiently advanced BS is indistinguishable from fact.
    
    
    Allen Brown wrote:
    > Actually, that doesn't work.
    >   cdlast foo bar/foobar
    > tries to go to ".".
    > 
    > In general I prefer to use $() syntax rather than the older ``
    > syntax. I think it is more readable.  And it is recursive, where
    > `` is not.  Also, using $() syntax means that you don't need to
    > escape the inner quotes.  The function below does the right thing
    > as far as I know.
    > 
    > function cdlast { cd "$(dirname "$_")"; }
    
  • [Eug-lug] stupid bash question



    Allen BrownTue Mar 15 11:00:52 PST 2005

    Actually, that doesn't work.
       cdlast foo bar/foobar
    tries to go to ".".
    
    In general I prefer to use $() syntax rather than the older ``
    syntax. I think it is more readable.  And it is recursive, where
    `` is not.  Also, using $() syntax means that you don't need to
    escape the inner quotes.  The function below does the right thing
    as far as I know.
    
    function cdlast { cd "$(dirname "$_")"; }
    -- 
    Allen Brown
       work: Agilent Technologies      non-work: http://www.peak.org/~abrown/
             allen_brown at agilent.com	            abrown at peak.org
       Television--a medium.  So called because it is neither rare
       nor well done. ---Ernie Kovacs
    
    
    Bob Miller wrote:
    > Bob Miller wrote:
    > 
    > 
    >>function cdlast { cd `dirname $_`; }
    > 
    > 
    > Correction:
    > 
    > function cdlast { cd "`dirname \"$_\"`"; }
    > 
    > Now it works even if the path has spaces or other punctuation in it.
    > And it looks slightly less obvious. (-:
    > 
    
  • [Eug-lug] stupid bash question



    Bob MillerTue Mar 15 09:43:41 PST 2005

    Hal Pomeranz wrote:
    
    > Yep, that works.  Thanks Bob!  Remind me to give you a lovely Deer
    > Run shirt the next time I see you.
    
    Woo-hoo!  Nothing runs like a deer...
    
    -- 
    Bob Miller                              K<bob>
    kbobsoft software consulting
    http://kbobsoft.com                     kbob at jogger-egg.com
    
  • [Eug-lug] stupid bash question



    Bob MillerTue Mar 15 09:42:56 PST 2005

    Bob Miller wrote:
    
    > function cdlast { cd `dirname $_`; }
    
    Correction:
    
    function cdlast { cd "`dirname \"$_\"`"; }
    
    Now it works even if the path has spaces or other punctuation in it.
    And it looks slightly less obvious. (-:
    
    -- 
    Bob Miller                              K<bob>
    kbobsoft software consulting
    http://kbobsoft.com                     kbob at jogger-egg.com
    
  • [Eug-lug] stupid bash question



    Hal PomeranzTue Mar 15 09:26:05 PST 2005

    > > Does anybody have a solution for creating an alias or function that
    > > does the equivalent of "cd !$:h"?  I feel like I must be missing
    > > something obvious...
    > 
    > function cdlast { cd `dirname $_`; }
    
    Yep, that works.  Thanks Bob!  Remind me to give you a lovely Deer
    Run shirt the next time I see you.
    
    Wow, reading the bash manual page I see that $_ is even more highly
    magical in bash than it is in Perl.  Wacky.
    
    -- 
    Hal Pomeranz, Founder/CEO      Deer Run Associates      hal at deer-run.com
        Network Connectivity and Security, Systems Management, Training