File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed 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.
92
92
myarray=(one two three four)
93
93
94
94
subarray=(" ${myarray[@]: 0: 2} " )
95
- declare -p subarray # => subarray=([0]="one" [1]="two")
95
+ declare -p subarray
96
+ # => declare -a subarray=([0]="one" [1]="two")
96
97
97
98
subarray=(" ${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")
99
101
```
100
102
101
103
Omitting the length part means "from the offset to the end of the array":
102
104
103
105
``` bash
104
106
subarray=(" ${myarray[@]: 2} " )
105
- declare -p subarray # => subarray=([0]="three" [1]="four")
107
+ declare -p subarray
108
+ # => declare -a subarray=([0]="three" [1]="four")
106
109
```
107
110
108
111
## Passing an Array to a Function
109
112
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.
111
114
There are two main techniques to pass an array to a function.
112
115
113
116
### 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.
92
92
myarray=(one two three four)
93
93
94
94
subarray=(" ${myarray[@]: 0: 2} " )
95
- declare -p subarray # => subarray=([0]="one" [1]="two")
95
+ declare -p subarray
96
+ # => declare -a subarray=([0]="one" [1]="two")
96
97
97
98
subarray=(" ${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")
99
101
```
100
102
101
103
Omitting the length part means "from the offset to the end of the array":
102
104
103
105
``` bash
104
106
subarray=(" ${myarray[@]: 2} " )
105
- declare -p subarray # => subarray=([0]="three" [1]="four")
107
+ declare -p subarray
108
+ # => declare -a subarray=([0]="three" [1]="four")
106
109
```
107
110
108
111
## Passing an Array to a Function
109
112
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.
111
114
There are two main techniques to pass an array to a function.
112
115
113
116
### Pass the Elements
You can’t perform that action at this time.
0 commit comments