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 [email protected] +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
