help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Current working directory echoed to the terminal


From: Eric Blake
Subject: Re: [Help-bash] Current working directory echoed to the terminal
Date: Mon, 09 Apr 2012 17:33:10 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1

On 04/09/2012 05:07 PM, Bob Proulx wrote:
>> Unsure about the implications but for now I changed the two ‘cd -’
>> commands to ‘cd - > /dev/null’ and the directory name is no longer
>> echoed to the terminal.
> 
> The implications are that you are doing something as a workaround to
> stop doing something else that you set it up to do.  I think it is
> better to stop doing the thing you don't want it to do in the first
> place and then there isn't a need for a workaround.  Do you really
> need CDPATH set?

Careful, there's several issues here.

POSIX requires cd to give output in the following two situations:

If 'cd -' is used (regardless of CDPATH)
if 'cd $dir' is successfully resolved due to CDPATH being set

For the former, avoiding CDPATH has no effect.  But if you don't like
'cd - > /dev/null' for fear that it silences too much, you can rewrite
it as 'cd $OLDPWD' with no loss in generality and no output.

For the latter, unsetting CDPATH will indeed shut up cd, but that will
also happen if you ensure that CDPATH is not consulted (by anchoring
$dir - that is, if $dir starts with /, ./, or ../, it is anchored, and
CDPATH will not be consulted).  So it is always possible to write a
script that works without cd output regardless of whether CDPATH is set.

Finally, setting CDPATH in an interactive shell is highly useful.
Exporting CDPATH to scripts is highly dangerous.  Therefore, I recommend
that you NEVER export CDPATH; feel free to set it for your own
interactive use, but do not export it.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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