Timeline for Split single string into character array using ONLY bash
Current License: CC BY-SA 4.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 18, 2020 at 19:28 | history | edited | Cyrus | CC BY-SA 4.0 | description added |
| Feb 13, 2019 at 20:07 | history | edited | Cyrus | CC BY-SA 4.0 | description added |
| Aug 16, 2015 at 23:20 | comment | added | user79743 | Of course, if the last newline must be corrected, change the line given to: while read -N 1 c; do a+=("$c"); done <<< "$s"x and then erase the last newline and the x added: unset a[${#a[@]}-1]; unset a[${#a[@]}-1]. | |
| Aug 16, 2015 at 23:05 | comment | added | user79743 | The second option should be: while read -N 1 c; do a+=("$c"); done <<< "$s". The -N allows to read even newlines, and the quotes ("$c") avoid pathname expansion (and some other issues). | |
| Apr 20, 2015 at 14:15 | vote | accept | Gregg Leventhal | ||
| Apr 20, 2015 at 3:14 | comment | added | rici | The second one is nice but it only works (in this case) because you don't quote "$c", so it will drop whitespace and expand stars in $s. | |
| Apr 19, 2015 at 16:46 | history | edited | Cyrus | CC BY-SA 3.0 | added 183 characters in body |
| Apr 19, 2015 at 16:26 | history | edited | terdon♦ | CC BY-SA 3.0 | added missing variable for clarity |
| Apr 19, 2015 at 16:25 | history | answered | Cyrus | CC BY-SA 3.0 |