Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Aug 1999 07:37:04 -0700 (PDT)
From:      "Eric J. Schwertfeger" <ejs@bfd.com>
To:        Greg Lehey <grog@lemis.com>
Cc:        Brian Somers <brian@Awfulhak.org>, Roelof Osinga <roelof@nisser.com>, Patrick Seal <patseal@hyperhost.net>, freebsd-questions@FreeBSD.ORG
Subject:   Re: Bash: space in cd arg bug?
Message-ID:  <Pine.BSF.4.05.9908310725280.17815-100000@harlie.bfd.com>
In-Reply-To: <19990831115226.X13904@freebie.lemis.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9908310725280.17815-100000>