Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
syntax:arrays [2018/04/20 04:45]
tomroche add text on array copying
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 393: Line 393:
 $ set -x; foo=bar declare arr=( {1..10} ) $ set -x; foo=bar declare arr=( {1..10} )
 + foo=bar + foo=bar
-+ declare 'a=(1)' 'a=(2)' 'a=(3)' 'a=(4)' 'a=(5)'++ declare 'arr=(1)' 'arr=(2)' 'arr=(3)' 'arr=(4)' 'arr=(5)' '​arr=(6)'​ '​arr=(7)'​ '​arr=(8)'​ '​arr=(9)'​ '​arr=(10)'
  
 $ touch xy=foo $ touch xy=foo
 ++ touch xy=foo
 $ declare x[y]=* $ declare x[y]=*
 + declare '​x[y]=*'​ + declare '​x[y]=*'​
  • syntax/arrays.1524199559.txt
  • Last modified: 2018/04/20 04:45
  • by tomroche