Bug 1460926 - Indexing an Array in Bash is not working as expected
Indexing an Array in Bash is not working as expected
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: bash (Show other bugs)
7.4
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Siteshwar Vashisht
BaseOS QE - Apps
:
Depends On: 1392951
Blocks:
  Show dependency treegraph
 
Reported: 2017-06-13 03:39 EDT by Siteshwar Vashisht
Modified: 2017-06-19 10:27 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1392951
Environment:
Last Closed: 2017-06-19 10:27:33 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Comment 2 Siteshwar Vashisht 2017-06-19 10:27:33 EDT
Anything between '[' and ']' is evaluated as a math expression. I will explain each command one by one :

'echo ${r[abc]}':

Here 'abc' will be replaced with 0, so it returns the 0th element from the array.

echo ${r[---abc]}:

Here math expression is evaluated as '-(--abc)'. Since 'abc' is 0, it will evaluate to '-(-1)' -> '1'. So it returns 1st element from array.

echo ${r[---abc]}:

It's the same as previous expression, but 'abc' is set to '-1' due to previous command. It will evaluate to '-(-2)' -> '2'. It returns empty element because array does not have a second element.

This is not a bug in bash.

Note You need to log in before you can comment on or make changes to this bug.