Deutsch   English   Français   Italiano  
<vmvp3d$2671i$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.unix.shell
Subject: Re: Default PATH setting - reduce to something more sensible?
Date: Fri, 24 Jan 2025 11:13:00 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <vmvp3d$2671i$1@dont-email.me>
References: <vm5dei$2c7to$1@dont-email.me>
 <1a876l-53v.ln1@ID-313840.user.individual.net>
 <20250122120930.74@kylheku.com>
 <ccr96l-eot.ln1@ID-313840.user.individual.net>
 <vmthmu$3bb88$1@news.xmission.com> <20250123134647.436@kylheku.com>
 <87v7u5m9m5.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 24 Jan 2025 11:13:01 +0100 (CET)
Injection-Info: dont-email.me; posting-host="36489c0f4554701c0d6fd4073065c2d1";
	logging-data="2300978"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19CgOqX7EfCBMTKpJYm6Dc7"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
Cancel-Lock: sha1:idDUW7kzL2io4LvlJ4TeZ4P3vWo=
In-Reply-To: <87v7u5m9m5.fsf@nosuchdomain.example.com>
X-Enigmail-Draft-Status: N1110
Bytes: 3159

On 23.01.2025 23:46, Keith Thompson wrote:
> Kaz Kylheku <643-408-1753@kylheku.com> writes:
> [...]
>> The obvious situation is double quotes. Inside double quotes, parameter
>> expansion happens, but not tilde expansion (not to mention pathname
>> expansion (globbing) and perhaps some other things).
>>
>> So this won't work:
>>
>>  PATH="$PATH:~/bin"
>>
>>> Sorry I don't have details, but it is true nonetheless.
>>
>> There they are.
> [...]
> 
> In fact it probably will *partially* work.  As I mentioned elsethread,
> bash expands a leading ~ (or even ~username) in an element of $PATH when
> executing a command.

Interpretation of any _leading_ '~' is the documented behavior for
tilde expansion.

> 
> But if you run a program from the command line that invokes another
> program (say, a C program that calls system()), it won't treat that
> element of $PATH the same way.

I think the point is that the _shell_ expands the expression.

Whether you do PATH="~" or PATH='~' or PATH=\~ , in all cases you have
defined a variable value that contains '~', a tilde. Not an expanded
tilde-expression. So if you 'exec' a command that PATH variable (with
the literal tilde) will get passed to the executable environment (and
no shell interpretation takes place).

Use PATH=~ instead if you want it expanded.

> 
> For this and other reasons, though you *can* have a literal ~ in $PATH
> in bash, it's best to avoid it and use $HOME instead. 

Or use it correctly, unquoted and unescaped.

Janis

> A literal '$HOME'
> won't work at all, but that's less likely to be a problem if your at all
> aware of how double quotes work in the shell.
> 
> I suggest that bash's undocumented behavior is less than helpful.
> I'll probably submit a bug report.
>