🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash.bug
Article #947

Re: cd x y

#947
From: Chet Ramey
Date: Thu, 05 Nov 1992 11:07
52 lines
1878 bytes
>    > I'm using GNU bash 1.12.  Is this normal that cd accepts more than one
>    > argument, without complaining?
> 
>    Sure, it's normal.  sh accepts two arguments without complaint.
> 
> This is not because one sins that it becomes normal to sin.  Are you
> kidding me?  In case not, (Chet is usually a serious guy :-), let me
> attempt another phrasing:
> 
> 	Should cd accept more than one argument without complaining?
> 	Would'nt it be better if bash complained when this happens?

If you think sh compatibility is important, then it should not complain.

One can always put the following into ~/.bashrc:

cd()
{
	if [ $# -gt 1 ]; then
		echo "cd: too many arguments" 1>&2
		return 1
	fi
	builtin cd "$@"
}

In fact, if you want to go all the way to ksh, try this:

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
}

Chet


--
``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: <9211052107.AA18026.SM@odin.INS.CWRU.Edu>
Path: arc1-ca.pugleaf.net!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
References: chet@odin.ins.cwru.edu (Chet Ramey)

Show Full Headers
Complete Article Headers
Newsgroups: gnu.bash.bug
Path: arc1-ca.pugleaf.net!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
From: chet@odin.ins.cwru.edu (Chet Ramey)
Subject: Re: cd x y
Message-ID: <9211052107.AA18026.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: Thu, 5 Nov 1992 11:07:46 GMT
Approved: bug-bash@prep.ai.mit.edu
Lines: 53