Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
syntax:arrays [2018/08/22 06:49] ebersphi |
syntax:arrays [2019/11/03 16:45] (current) ersen fix a typo |
||
---|---|---|---|
Line 242: | Line 242: | ||
</code> | </code> | ||
- | ''a[0]'' is assigned to the result of ''2+4''. ''a[1]'' gets the result of ''2+2''. The last index in the first assignment is the result of ''a[2]'', which has already been assigned as ''4'', and its value is also given ''a[2]''. | + | ''a[0]'' is assigned to the result of ''2+4''. ''a[2]'' gets the result of ''2+2''. The last index in the first assignment is the result of ''a[2]'', which has already been assigned as ''4'', and its value is also given ''a[2]''. |
This shows that even though any existing arrays named ''a'' in the current scope have already been unset by using ''='' instead of ''+='' to the compound assignment, arithmetic variables within keys can self-reference any elements already assigned within the same compound-assignment. With integer arrays this also applies to expressions to the right of the ''=''. (See [[#evaluation_order | evaluation order]], the right side of an arithmetic assignment is typically evaluated first in Bash.) | This shows that even though any existing arrays named ''a'' in the current scope have already been unset by using ''='' instead of ''+='' to the compound assignment, arithmetic variables within keys can self-reference any elements already assigned within the same compound-assignment. With integer arrays this also applies to expressions to the right of the ''=''. (See [[#evaluation_order | evaluation order]], the right side of an arithmetic assignment is typically evaluated first in Bash.) | ||
Line 396: | Line 396: | ||
$ touch xy=foo | $ touch xy=foo | ||
+ | + touch xy=foo | ||
$ declare x[y]=* | $ declare x[y]=* | ||
+ declare 'x[y]=*' | + declare 'x[y]=*' |