Timeline for BASH associative array printing
Current License: CC BY-SA 3.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 23, 2017 at 1:12 | comment | added | Nadreck | My bad! Got my _tr_s and _sed_s totally mixed up! Fixed in the latest edit. | |
| May 23, 2017 at 1:10 | comment | added | Nadreck | Very true about some of the non-alphanumeric characters gumming this up. However anything that has to deal them gets an order of magnitude more complex and less readable so unless there's a really good reason to have them in your data feed and that's stated in the question I assume they're filtered out before we got here. Should always have your explicit caveat tho. I find these pipelines to be simpler, for example and debugging purposes, than a printf glob that either works perfectly or blows up in your face. Here you make one simple change per element, test it, then add 1 more. | |
| May 23, 2017 at 0:30 | history | edited | Nadreck | CC BY-SA 3.0 |
Had my seds and tr s mixed up!
|
| May 22, 2017 at 21:22 | comment | added | ilkkachu |
Also, you do know that tr translate character-by-character, it doesn't match strings? tr "]=" " =" changes "]" to a space and an = to an =, regardless of position. So you could probably just combine all three tr's to one.
|
|
| May 22, 2017 at 21:19 | comment | added | ilkkachu |
That kind of a pipeline is bound to fail the moment some of the keys or values of the array contain any of the characters you're replacing, like parenthesis, brackets or quotes. And a pipeline of seds and tr's isn't even much simpler than a for loop with printf.
|
|
| May 22, 2017 at 19:36 | history | answered | Nadreck | CC BY-SA 3.0 |