On 3/6/18 11:38 PM, christopher barry wrote:

> Bash Version: 4.4 (does not work)
> Patch Level: 12
> Release Status: release
> Description:
> a simple function that is used to test if a var is indirect or not and
> return the value whether indirect or simply a string is no longer
> working as expected on newer versions of bash.
> Repeat-By:
> This function works fine on this version (4.3.43) of bash (and
> all previous versions I have access to, e.g. 4.2.46). It is broken, that
> I am aware of, in 4.4.12 and 4.4.19, and possibly other versions as
> well.
>  function ivar() { echo -n "${!1:-${1}}"; }
> This will take in a word as $1, and if it is a ref, will echo the
> value of ref, but if it is not, will simply echo $1. This function
> cares not about the string handed in, it rejects the indirection
> silently, and IMHO correctly, regardless of the characters in that
> string. I have found this function to be incredibly handy, and it's in
> extensive use. It's simplicity and usefulness are very much relied upon.
> Now, if the string starts with a number, or has a dash (possibly other
> chars as well), it throws a syntax error. It's not clear to me why it
> now feels the need to do this.

The strings you're describing are invalid variable names. They would
generate variable expansion errors if used directly; why should they not
generate the same error when used as the value of an indirect expansion?
The two cases are supposed to be identical.

These should all generate errors (and in bash-4.4, they generate the same
`bad substitution' error):

echo "${-3:-${-3}}";
echo ${-3}

echo ${!x}

function ivar() { echo -n "${!1:-${1}}"; }
ivar -3

It was a bug in bash-4.3 that the latter two cases didn't produce errors,
and, in the `!x' case, produced random output and occasional core dumps.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to