Article View: gnu.bash.bug
Article #970Re: Missing functionality from BASH ?
From: Chet Ramey
Date: Mon, 14 Dec 1992 05:32
Date: Mon, 14 Dec 1992 05:32
45 lines
2177 bytes
2177 bytes
> a) CDSPELL. In ksh (or at least on SCO's ksh), if you mis-type a directory
> name, cd finds the closes matching directory, and prompts you for a
> y/n entry. Each time you say no to a directory, it carries on seaching
> down CDPATH for another possible match. Only one the end of all possible
> directories have been refused as options, does cd report that the directory
> does not exist.
This is not a feature of `standard' ksh. SCO must have added it. It's
not in Posix.2.
> b) cd name substitution. If your current directory is, say /usr/spool/uucp
> and you type in 'cd spool lib', ksh changes you to /usr/lib/uucp. ksh
> substitutes the second parameter for that portion of PWD that matches
> the first parameter. Very usefull feature that.
This is not in Posix.2 either, but is easily added with a function. Bash
allows a function to replace a builtin, and provides the `builtin' keyword
to make the functionality of the builtin available to the function. Here,
for instance, is a shell function that provides all of the functionality
of the ksh `cd', including the name substitution.
cd()
{
case $# in
0) builtin cd "$HOME" ;;
1) builtin cd "$@" ;;
2) old="$1"
new="$2"
dir=$(echo "$PWD" | sed "s:$old:$new:g")
case "$dir" in
"$PWD") echo "bash: cd: bad substitution" >&2 ; return 1 ;;
*) echo "$dir"
builtin cd "$dir"
;;
esac
;;
*) echo "cd: wrong arg count" >&2 ; return 1 ;;
esac
}
--
``The use of history as therapy means the corruption of history as history.''
-- Arthur Schlesinger
Chet Ramey, Case Western Reserve University Internet: chet@po.CWRU.Edu
Technical Details
Message-ID:
<9212141532.AA18629.SM@odin.INS.CWRU.Edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chetReferences:
chet@odin.ins.cwru.edu (Chet Ramey)Show Full Headers
Complete Article Headers
Newsgroups: gnu.bash.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chet From: chet@odin.ins.cwru.edu (Chet Ramey) Subject: Re: Missing functionality from BASH ? Message-ID: <9212141532.AA18629.SM@odin.INS.CWRU.Edu> Sender: gnulists@ai.mit.edu Reply-To: chet@po.cwru.edu Organization: GNUs Not Usenet References: chet@odin.ins.cwru.edu (Chet Ramey) Distribution: gnu Date: Mon, 14 Dec 1992 05:32:08 GMT Approved: bug-bash@prep.ai.mit.edu Lines: 46