Timeline for Passing arrays in to the function in bash script
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 23, 2020 at 9:44 | history | edited | Paul_Pedant | CC BY-SA 4.0 |
Removed incorrect assertion about arrays as function arguments.
|
| May 23, 2020 at 9:38 | comment | added | Paul_Pedant | @StéphaneChazelas Had I not tested this, I would not have had the opportunity to be astonished. But it has vanished from my history, and I can't reconstruct what I thought I did. So conceded and edited. I did run across this construct which lets you alter global arrays by variable name from within functions: declare -g "$1[4]=abc"; | |
| May 22, 2020 at 12:01 | comment | added | glenn jackman |
Yes, the index part of an indexed array element notation is an arithmetic expression, and the $ is not required for shell variables in an arithmetic expression: "${N[n]}"
|
|
| May 22, 2020 at 11:05 | comment | added | Stéphane Chazelas |
Note that you can also do ${files[i]} which saves the double translation between integer and number.
|
|
| May 22, 2020 at 11:04 | comment | added | Stéphane Chazelas |
What do you mean by "${1[${i}]}" works? I get a bad substitution error in bash 5.0.16
|
|
| May 22, 2020 at 11:01 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
added 12 characters in body
|
| May 22, 2020 at 10:10 | history | answered | Paul_Pedant | CC BY-SA 4.0 |