[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] docs: mention cd limitation

From: Eric Blake
Subject: Re: [PATCH 1/2] docs: mention cd limitation
Date: Sat, 31 Jul 2010 10:27:24 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100720 Fedora/3.1.1-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.3 Thunderbird/3.1.1

On 07/31/2010 03:24 AM, Paolo Bonzini wrote:
> On 07/30/2010 12:24 AM, Eric Blake wrote:
>> +Posix states that behavior is undefined if @command{cd} is given an
>> +explicit empty argument.  Some shells do nothing, some change to the
>> +first entry in @env{CDPATH}, some change to @env{HOME}, and some exit
>> +the shell rather than returning an error.  Unfortunately, this means
>> +that if @samp{$var} is empty, then @samp{cd "$var"} is less predictable
>> +than @samp{cd $var} (at least the latter is well-behaved in all shells
>> +at changing to @env{HOME}, although this is probably not what you wanted
>> +in a script).  You should check that a directory name was supplied
>> +before trying to change locations.
> bash's behavior is to do nothing.

Actually, bash's behavior is to change to the first directory in CDPATH.

>  We may suggest
>   cd "${var:-.}"
> which is the closest thing to a sensible behavior (better than changing
> to HOME...).

Hmm, good idea.  Another idea is:

cd "${var:/nosuch}" to force a non-zero exit status.

Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]