Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14453

Re: Tilde expansion in assignment-like context

From Clint Hepner <clint.hepner@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Tilde expansion in assignment-like context
Date 2018-08-06 16:04 -0400
Message-ID <mailman.4768.1533585881.1292.bug-bash@gnu.org> (permalink)
References <349F67EA-6EA7-4C8E-8E3A-AC36A82EBFBD@gmail.com> <3f04a0db-0583-d5d9-1faf-75deb76c1219@case.edu>

Show all headers | View raw


> On 2018 Aug 6 , at 3:45 p, Chet Ramey <chet.ramey@case.edu> wrote:
> 
> On 8/6/18 3:09 PM, Clint Hepner wrote:
> 
>> Bash Version: 4.4
>> Patch Level: 19
>> Release Status: release
>> 
>> Description:
>>        A non-initial unquoted tilde is expanded outside of an assignment. This
>>        was raised as a question on Stack Overflow, https://stackoverflow.com/q/51713759/1126841.
>> 
>> Repeat-By:
>> 
>>        $ set +k
>>        $ echo home_dir=~
>>        home_dir=/Users/chepner
> 
> Yes. Bash has done this since its earliest days. A word that looks like an
> assignment statement has tilde expansion performed after unquoted =~ and :~
> no matter where it appears on the command line. This makes things like
> 
> 	make DESTDIR=~stager/bash-install
> or
> 	export PATH=/usr/local/bin:~/bin:/usr/bin
> 
> easy and convenient.

Oh, right. For some reason, I had it in my head that this was only intended
for builtins like export, and that their status as builtins somehow made
the argument be treated as an assignment. I hadn't thought at all about non-builtin
commands like make.

> 
> The first version I can find that implemented the =~ and :~ tilde expansion
> prefixes is bash-1.10 (1991). Those early versions would have expanded
> something like `--home_dir=~'. The first version that restricted it to
> words that satisfied the assignment statement restrictions is bash-2.0
> (1996).
> 
> Bash doesn't do this when it's in posix mode. The first version that
> implemented that was bash-1.14.0.
> 
> -- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> 		 ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Tilde expansion in assignment-like context Clint Hepner <clint.hepner@gmail.com> - 2018-08-06 16:04 -0400

csiph-web