zsh-workers
 help / color / mirror / code / Atom feed
From: Ulrik Haugen <qha@lysator.liu.se>
To: zsh-workers@sunsite.dk
Subject: Re: BUG: cd '' doesn't produce an error
Date: Fri, 30 Dec 2005 13:52:42 +0100	[thread overview]
Message-ID: <877j9mycf9.fsf@haugen.visit.se> (raw)
In-Reply-To: <20051221102159.44d9f5ca.pws@csr.com>

Hello!

Peter Stephenson <pws@csr.com> wrote:

> Ulrik Haugen <qha@lysator.liu.se> wrote:
>> I recently discovered that zsh (versions 4.2.5 and 4.3.0-dev-1)
>> doesn't produce an error when i attempt to "cd ''" (in version 3.0.8 I
>> get the error i expected). Please let me know if you'd like me to test
>> any other versions.

> It's certainly strange, although it's not wholly illogical with $cdpath: as
> the empty string is not an absolute directory nor begins with . or .., the
> shell looks through $cdpath for the first directory for which the
> concatenation with the empty string exists, which is usually just the first
> directory in $cdpath.  This is almost useful...  It's easy to add an error
> but I'm not quite sure at what stage the behaviour actually is an error in
> this case: it's a correct, if unexpected, interpretation of the cdpath
> rules.

Sorry for taking so long to reply, but I haven't had the time to look
into properly this until now.

I'm still not quite satisfied with this behaviour for a couple of
reasons:

In my tests I had not set cdpath, so I don't see why the shell should
go through any cdpath rules.


If I try
% cd /tmp; CDPATH=/usr cd ''
I still wind up in /tmp, so it doesn't seem to have that much to do
with cdpath to me.


If I had ended ended up in /usr, I'm not really sure I'd like that
either (although someone who uses cdpath is probably a better judge).
My intuitive expectation was that cd would successively cd to each
component of cdpath, try to cd to the argument given and be satisfied
at the first successful cd (though obviously just appending "/$arg" to
each component in cdpath and successively trying to cd to that is
cheaper).





The reason I take the time to argue about this is that I often want to
determine the absolute path my scripts are called from in this
fashion:

scriptdir=`dirname "$0"`
scriptdir=`cd "$scriptdir"&& pwd`

More than once I've decided I'm not happy with whatever variable name
has had the role of scriptdir and only changed the occurences at the
beginnings of lines. Right now zsh silently ignores my error and I'll
get the callers present working directory in the whatever new name
I've chosen for scriptdir. Admittedly I'd get a faulty value if zsh
complained to, but at least I'd get some indication of my mistake.


  reply	other threads:[~2005-12-30 12:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-21  2:03 Ulrik Haugen
2005-12-21 10:21 ` Peter Stephenson
2005-12-30 12:52   ` Ulrik Haugen [this message]
2005-12-30 16:28     ` Wayne Davison
2006-01-04 17:32       ` Wayne Davison
2006-01-04 19:48       ` Ulrik Haugen
2006-01-04 11:41     ` Peter Stephenson
2006-01-04 13:06       ` Peter Stephenson
2006-01-04 17:48       ` Peter Stephenson
2006-01-04 22:30       ` Ulrik Haugen
2006-01-05 12:29         ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877j9mycf9.fsf@haugen.visit.se \
    --to=qha@lysator.liu.se \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).