home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / gnu / bash / bug / 652 < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.8 KB  |  68 lines

  1. Newsgroups: gnu.bash.bug
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!ames!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chet
  3. From: chet@odin.ins.cwru.edu (Chet Ramey)
  4. Subject: Re: cd x y
  5. Message-ID: <9211052107.AA18026.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: Thu, 5 Nov 1992 11:07:46 GMT
  12. Approved: bug-bash@prep.ai.mit.edu
  13. Lines: 53
  14.  
  15. >    > I'm using GNU bash 1.12.  Is this normal that cd accepts more than one
  16. >    > argument, without complaining?
  17. >    Sure, it's normal.  sh accepts two arguments without complaint.
  18. > This is not because one sins that it becomes normal to sin.  Are you
  19. > kidding me?  In case not, (Chet is usually a serious guy :-), let me
  20. > attempt another phrasing:
  21. >     Should cd accept more than one argument without complaining?
  22. >     Would'nt it be better if bash complained when this happens?
  23.  
  24. If you think sh compatibility is important, then it should not complain.
  25.  
  26. One can always put the following into ~/.bashrc:
  27.  
  28. cd()
  29. {
  30.     if [ $# -gt 1 ]; then
  31.         echo "cd: too many arguments" 1>&2
  32.         return 1
  33.     fi
  34.     builtin cd "$@"
  35. }
  36.  
  37. In fact, if you want to go all the way to ksh, try this:
  38.  
  39. cd()
  40. {
  41.     case $# in
  42.     0)    builtin cd "$HOME" ;;
  43.     1)     builtin cd "$@" ;;
  44.     2)    old="$1"
  45.         new="$2"
  46.         dir=$(echo "$PWD" | sed "s:$old:$new:g")
  47.         case "$dir" in
  48.         "$PWD")    echo "bash: cd: bad substitution" >&2 ; return 1 ;;
  49.         *)    echo "$dir" ; builtin cd "$dir" ;;
  50.         esac
  51.         ;;
  52.     *)    echo "cd: wrong arg count" >&2 ; return 1 ;;
  53.     esac
  54. }
  55.  
  56. Chet
  57.  
  58.  
  59. --
  60. ``The use of history as therapy means the corruption of history as history.''
  61.     -- Arthur Schlesinger
  62.  
  63. Chet Ramey, Case Western Reserve University    Internet: chet@po.CWRU.Edu
  64.  
  65.