[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bash 4.4.5] Variable indirection, error on empty variable
From: |
Chet Ramey |
Subject: |
Re: [Bash 4.4.5] Variable indirection, error on empty variable |
Date: |
Tue, 29 Nov 2016 09:19:39 -0800 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 |
On 11/27/16 5:07 AM, Otenba wrote:
> Bash Version: 4.4
> Patch Level: 5
> Release Status: release
>
> Description:
> Performing variable indirection using an empty value causes an error. It
> didn't in Bash 4.3.
It's pretty clear that indirect expansion that attempts to reference
through an unset variable or a variable whose value is null should be an
error. Bash-4.3 didn't have the greatest error checking, and bash-4.4
catches the null value case. I'll fix it to catch the unset variable
case, too.
> Repeat-By:
> $ reference=1
> $ echo ${!indirect} #variable indirection using an unset variable
If you think of indirect expansion as just a simple string replacement,
though it's more complicated than that, it's clear that this is logically
equivalent to echo ${}, which should be an error.
> $ indirect=
> $ echo ${!indirect} #variable indirection using an empty variable
> -bash: : bad substitution
Using the same logic as above, this expands to the equivalent of
echo ${" "}, which is another obvious error, though the message could
be a little better.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/