bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some minor notes on manual chapter 4 "Shell Builtin Commands"


From: Chet Ramey
Subject: Re: Some minor notes on manual chapter 4 "Shell Builtin Commands"
Date: Mon, 9 Oct 2023 14:51:29 -0400
User-agent: Mozilla Thunderbird

On 10/9/23 12:25 PM, Robert Elz wrote:
     Date:        Mon, 9 Oct 2023 10:35:20 -0400
     From:        Chet Ramey <chet.ramey@case.edu>
     Message-ID:  <a9e4d016-de50-4b67-a688-590ff0a77c13@case.edu>

   | There is surprising variance in behavior here, from a status of 2 to 1
   | to 0 (dash), plus the silly ksh "substitute old for new in $PWD," which
   | the NetBSD sh (!) also performs.

Yes, we do...  it is surprisingly useful behaviour, and has been there
for a long time (Nov 2002, so it isn't going away)

Sure, if people want it there's a shell function in the bash distribution
that does the same thing using the ${var//pat/rep} expansion.

but it doesn't really need to be in the shell,

That's my beef, but, strictly speaking, neither do pushd/popd/dirs.

the following cd replacement func (which I use
in bash, and other shells that don't support this) adds good enough
support for it (not perfect, it doesn't always do the expected thing
if the same arg string occurs multiple times in $PWD - that's very rare):


You might consider the ${param//old/new} expansion if it's available.


ps: This is useful when you're working with lots of source trees in parallel,
like /release/8/long/path/to/sources/being/examined and /release/9/... and
/release/10/...   so one can just do "cd 8 9" or "cd 8 10" (etc) to switch
from one tree to the other.

The directory stack is good for this as well, but it can get kind of
unwieldy to keep track of what's where. I don't usually work with more
than two directories at once, for which `cd -' suffices.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]