From owner-freebsd-questions Tue Aug 31 7:39: 9 1999 Delivered-To: freebsd-questions@freebsd.org Received: from horst.bfd.com (horst.bfd.com [12.9.219.10]) by hub.freebsd.org (Postfix) with ESMTP id 7E05C15936 for ; Tue, 31 Aug 1999 07:39:06 -0700 (PDT) (envelope-from ejs@bfd.com) Received: from HARLIE.bfd.com (bastion.bfd.com [12.9.219.14]) by horst.bfd.com (8.9.3/8.9.2) with ESMTP id HAA11784; Tue, 31 Aug 1999 07:37:04 -0700 (PDT) (envelope-from ejs@bfd.com) Date: Tue, 31 Aug 1999 07:37:04 -0700 (PDT) From: "Eric J. Schwertfeger" To: Greg Lehey Cc: Brian Somers , Roelof Osinga , Patrick Seal , freebsd-questions@FreeBSD.ORG Subject: Re: Bash: space in cd arg bug? In-Reply-To: <19990831115226.X13904@freebie.lemis.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 31 Aug 1999, Greg Lehey wrote: > On Tuesday, 31 August 1999 at 0:02:20 +0100, Brian Somers wrote: > > [.....] > >>> You missed the > >>> > >>> zsh -> echo $FOO > >>> /C:/Program Files > >>> zsh -> mkdir $FOO > >>> > >>> Which makes two directories. Why should ``cd'' behave differently > >>> from an external command - just because it's a builtin ? > >> > >> It shouldn't. > >> > >>> IMHO, zsh is wrong. > >> > >> Agreed. And bash does exactly the same thing in this case. > > > > Someone said that ``cd $FOO'' was being interpreted as > > ``cd "Program Files"'' (two words) rather than as > > ``cd Program Files'' (three words). The correct interpretation > > (which is the same as bash's interpretation) is as three words. > > Why is this correct? How do I store a directory name which contains > in a variable and then change to it? It's not correct just to cd $* > instead of cd $1, because there could be multiple contiguous spaces in > the directory name. because then you'd either break scripts that do things like this, or be rather inconsistent? (Not a realworld example, but the simplest case that shows my point). FILES=$(ls /tmp); for i in $FILES; do ls -l $i done If DIR contains a directory that might contain spaces, I'd say the only proper use of DIR would be cd "$DIR" Likewise, cd "$1" (if you thought cd "$*" as I did at first, shame on you, you should have quoted the directory name on the command line, hence getting it all into $1.) Yes, I think having spaces in filennames or directory names is wrong, but it's getting rather hard to fight this one. This is one of the reasons I do most of the work I used to do in shell script in perl now. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message