[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Positional parameter/Array slicing bug with empty arguments
From: |
Theodoros V. Kalamatianos |
Subject: |
Positional parameter/Array slicing bug with empty arguments |
Date: |
Sun, 12 Jan 2014 02:01:56 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
I have bumped into a rather strange issue:
$ set -- ''; printf "=%s=\n" "$@" x
==
=x=
$ set -- ''; printf "=%s=\n" "${@:1}" x
=x=
Notice how in the second version the empty positional parameter is no
longer displayed. Also compare with this version:
$ set -- '' ''; printf "=%s=\n" "${@:1}" x
=x=
==
==
Now both empty arguments appear nornally. Also this check verifies that
this is not a `printf' issue:
$ set -- ''; set -- "${@:1}"; echo "$#"
0
It seems that the issue has something to do with expanding a slice with
a single empty element:
$ set -- '' ''; printf "=%s=\n" "${@:1:1}" x
=x=
The same issue also happens with arrays:
$ A=('' ''); printf "=%s=\n" "${A[@]:0}" x
==
==
=x=
$ A=('' ''); printf "=%s=\n" "${A[@]:0:1}" x
=x=
$ A=('' ''); printf "=%s=\n" "${A[@]:1}" x
=x=
I encountered this on bash-4.2.037, as provided by the Mageia 3 Linux
distribution, but according to a contact on IRC, this issue also affects
the latest patch (4.2.045).
I would be happy to provide any information that you may need.
Best regards,
Theodoros V. Kalamatianos
- Positional parameter/Array slicing bug with empty arguments,
Theodoros V. Kalamatianos <=