Timeline for BASH associative array printing
Current License: CC BY-SA 4.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 5 at 17:02 | history | edited | F. Hauri - Give Up GitHub | CC BY-SA 4.0 |
added 84 characters in body
|
| Jul 14, 2022 at 6:38 | history | edited | F. Hauri - Give Up GitHub | CC BY-SA 4.0 |
added 117 characters in body
|
| Jan 2, 2018 at 1:44 | history | edited | Jeff Schaller♦ | CC BY-SA 3.0 |
minor grammatical tweaks
|
| May 23, 2017 at 12:23 | history | edited | F. Hauri - Give Up GitHub | CC BY-SA 3.0 |
added 123 characters in body
|
| May 23, 2017 at 6:47 | history | edited | F. Hauri - Give Up GitHub | CC BY-SA 3.0 |
added 2 characters in body
|
| May 23, 2017 at 6:42 | comment | added | F. Hauri - Give Up GitHub |
@StéphaneChazelas You're right: <(builtin) is a fork, but exertnal pr is a fork too. I will re-count...
|
|
| May 23, 2017 at 6:31 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
missing quotes
|
| May 23, 2017 at 6:28 | comment | added | Stéphane Chazelas |
In bash, cmd1 | cmd2 means 2 forks, even if cmd1 or cmd2 or both are builtin.
|
|
| May 23, 2017 at 6:23 | history | edited | F. Hauri - Give Up GitHub | CC BY-SA 3.0 |
added 1623 characters in body
|
| May 23, 2017 at 4:12 | comment | added | Satō Katsura |
@ilkkachu Then, while we are at it, using echo is wrong too, since $i can begin with a dash. :) printf should be used instead.
|
|
| May 22, 2017 at 21:45 | comment | added | ilkkachu |
That last snippet with paste is longer than the for loop in the question written on one line for i in "${!array[@]}"; do echo "$i=${array[$i]}" ; done, but requires two subshells and an external program. How is that neater? The solution with pr also breaks if there are many elements, as it tries to paginate the output. You'd need to use something like | pr -2t -l"${#array[@]}" which is starting to get hard to remember compared to the simple loop, and again, is longer than it.
|
|
| May 22, 2017 at 19:48 | comment | added | MiniMax | @SatoKatsura Yes, I missed it. | |
| May 22, 2017 at 19:30 | comment | added | Satō Katsura |
@MiniMax Because it doesn't produce the correct result (same elements, wrong order). You'd need to zip arrays ${!array[@]} and ${array[@]} first for that to work.
|
|
| May 22, 2017 at 18:35 | comment | added | MiniMax |
For last example (paste -d), why haven't do so: printf "%s=%s\n" "${!array[@]}" "${array[@]}"? The same result, but more simple.
|
|
| May 22, 2017 at 17:14 | comment | added | F. Hauri - Give Up GitHub |
@SatoKatsura I agree, but if slower, syntax using pr is shorter... I'm not sure about pr syntax stay slower, even with big arrays!
|
|
| May 22, 2017 at 16:50 | comment | added | Satō Katsura |
While looking clever, both ways are less efficient than a for. Which is a shame, really.
|
|
| May 22, 2017 at 16:30 | history | answered | F. Hauri - Give Up GitHub | CC BY-SA 3.0 |