home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / gnu / bash / bug / 701 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.1 KB  |  61 lines

  1. Newsgroups: gnu.bash.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chet
  3. From: chet@odin.ins.cwru.edu (Chet Ramey)
  4. Subject: Re: Missing functionality from BASH ?
  5. Message-ID: <9212141532.AA18629.SM@odin.INS.CWRU.Edu>
  6. Sender: gnulists@ai.mit.edu
  7. Reply-To: chet@po.cwru.edu
  8. Organization: GNUs Not Usenet
  9. References: chet@odin.ins.cwru.edu (Chet Ramey)
  10. Distribution: gnu
  11. Date: Mon, 14 Dec 1992 05:32:08 GMT
  12. Approved: bug-bash@prep.ai.mit.edu
  13. Lines: 46
  14.  
  15. > a) CDSPELL. In ksh (or at least on SCO's ksh), if you mis-type a directory
  16. >    name, cd finds the closes matching directory, and prompts you for a
  17. >    y/n entry. Each time you say no to a directory, it carries on seaching
  18. >    down CDPATH for another possible match. Only one the end of all possible
  19. >    directories have been refused as options, does cd report that the directory
  20. >    does not exist.
  21.  
  22. This is not a feature of `standard' ksh.  SCO must have added it.  It's
  23. not in Posix.2.
  24.  
  25. > b) cd name substitution. If your current directory is, say /usr/spool/uucp
  26. >    and you type in 'cd spool lib', ksh changes you to /usr/lib/uucp. ksh
  27. >    substitutes the second parameter for that portion of PWD that matches
  28. >    the first parameter. Very usefull feature that.
  29.  
  30. This is not in Posix.2 either, but is easily added with a function.  Bash
  31. allows a function to replace a builtin, and provides the `builtin' keyword
  32. to make the functionality of the builtin available to the function.  Here,
  33. for instance, is a shell function that provides all of the functionality
  34. of the ksh `cd', including the name substitution.
  35.  
  36. cd()
  37. {
  38.     case $# in
  39.     0)    builtin cd "$HOME" ;;
  40.     1)     builtin cd "$@" ;;
  41.     2)    old="$1"
  42.         new="$2"
  43.         dir=$(echo "$PWD" | sed "s:$old:$new:g")
  44.         case "$dir" in
  45.         "$PWD")    echo "bash: cd: bad substitution" >&2 ; return 1 ;;
  46.         *)    echo "$dir"
  47.             builtin cd "$dir"
  48.             ;;
  49.         esac
  50.         ;;
  51.     *)    echo "cd: wrong arg count" >&2 ; return 1 ;;
  52.     esac
  53. }
  54.  
  55. --
  56. ``The use of history as therapy means the corruption of history as history.''
  57.     -- Arthur Schlesinger
  58.  
  59. Chet Ramey, Case Western Reserve University    Internet: chet@po.CWRU.Edu
  60.  
  61.