From owner-freebsd-questions Mon Aug 30 20:59: 0 1999 Delivered-To: freebsd-questions@freebsd.org Received: from mailgw02.execpc.com (mailgw02.execpc.com [169.207.3.78]) by hub.freebsd.org (Postfix) with ESMTP id 75A2214F86 for ; Mon, 30 Aug 1999 20:58:55 -0700 (PDT) (envelope-from hamilton@pobox.com) Received: from woodstock.monkey.net (mercury-1-74.mdm.mkt.execpc.com [169.207.87.74]) by mailgw02.execpc.com (8.9.1) id WAA31793; Mon, 30 Aug 1999 22:57:26 -0500 Received: from pobox.com (localhost [127.0.0.1]) by woodstock.monkey.net (Postfix) with ESMTP id 43D82A0; Mon, 30 Aug 1999 22:57:50 -0500 (CDT) 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: Your message of "Tue, 31 Aug 1999 11:52:27 +0930." <19990831115226.X13904@freebie.lemis.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 30 Aug 1999 22:57:50 -0500 From: Jon Hamilton Message-Id: <19990831035750.43D82A0@woodstock.monkey.net> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <19990831115226.X13904@freebie.lemis.com>, 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. [501] hamilton@woodstock /tmp$ FOO=my\ directory\ name\ with\ spaces [502] hamilton@woodstock /tmp$ echo $FOO my directory name with spaces [503] hamilton@woodstock /tmp$ cd "$FOO" [504] hamilton@woodstock my\ directory\ name\ with\ spaces$ pwd /tmp/my directory name with spaces I think you are trying to be pedantic, but I'm not sure that your wishes are consistent with the way the shell operates, and with historic operation of sh. What other circumstance can you think of in which an unquoted parameter expansion containing spaces results in words not being broken at each whitespace sequence? -- Jon Hamilton hamilton@pobox.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message