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:
Tue, 10 Apr 2012 08:32:48 -0600
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1
On 04/09/2012 09:48 PM, Chris Jones wrote:
>> 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.
>
> I kinda like this approach better on principle. What do you have in mind
> when you state ‘silences too much’? Could cd try to write something else
> to stdout?
Technically, no; cd writes to stderr on errors, and only to stdout on
success. It boils down to aesthetics on this case.
>
>> 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.
>
> A bit over my head, but in any event, I don't use CDPATH.. as I see it,
> it would just be another piece of data that I'd have to maintain.
The executive summary: 1. Although _you_ might not use CDPATH, you
should write your scripts so that they are robust in case someone else
uses CDPATH (by always using absolute paths and/or prefixing with ./).
2. If you _do_ use CDPATH, set it as a shell variable, but don't export
it, since not all scripts follow point 1.
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc Description: OpenPGP digital signature