File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,22 +92,25 @@ We can do the same thing with arrays to expand a slice of the array.
9292myarray=(one two three four)
9393
9494subarray=(" ${myarray[@]: 0: 2} " )
95- declare -p subarray # => subarray=([0]="one" [1]="two")
95+ declare -p subarray
96+ # => declare -a subarray=([0]="one" [1]="two")
9697
9798subarray=(" ${myarray[@]: 1: 3} " )
98- declare -p subarray # => subarray=([0]="two" [1]="three" [2]="four")
99+ declare -p subarray
100+ # => declare -a subarray=([0]="two" [1]="three" [2]="four")
99101```
100102
101103Omitting the length part means "from the offset to the end of the array":
102104
103105``` bash
104106subarray=(" ${myarray[@]: 2} " )
105- declare -p subarray # => subarray=([0]="three" [1]="four")
107+ declare -p subarray
108+ # => declare -a subarray=([0]="three" [1]="four")
106109```
107110
108111## Passing an Array to a Function
109112
110- This is not as straightforward as other languages you might be know.
113+ This is not as straightforward as other languages you might know.
111114There are two main techniques to pass an array to a function.
112115
113116### Pass the Elements
Original file line number Diff line number Diff line change @@ -92,22 +92,25 @@ We can do the same thing with arrays to expand a slice of the array.
9292myarray=(one two three four)
9393
9494subarray=(" ${myarray[@]: 0: 2} " )
95- declare -p subarray # => subarray=([0]="one" [1]="two")
95+ declare -p subarray
96+ # => declare -a subarray=([0]="one" [1]="two")
9697
9798subarray=(" ${myarray[@]: 1: 3} " )
98- declare -p subarray # => subarray=([0]="two" [1]="three" [2]="four")
99+ declare -p subarray
100+ # => declare -a subarray=([0]="two" [1]="three" [2]="four")
99101```
100102
101103Omitting the length part means "from the offset to the end of the array":
102104
103105``` bash
104106subarray=(" ${myarray[@]: 2} " )
105- declare -p subarray # => subarray=([0]="three" [1]="four")
107+ declare -p subarray
108+ # => declare -a subarray=([0]="three" [1]="four")
106109```
107110
108111## Passing an Array to a Function
109112
110- This is not as straightforward as other languages you might be know.
113+ This is not as straightforward as other languages you might know.
111114There are two main techniques to pass an array to a function.
112115
113116### Pass the Elements
You can’t perform that action at this time.
0 commit comments