Timeline for How do I split a string on a delimiter in Bash?
Current License: CC BY-SA 2.5
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 1, 2019 at 14:36 | comment | added | Steven the Easily Amused | A problem with this, and many other solutions is also that it assumes there are EXACTLY TWO elements in $IN - OR that you're willing to have the second and subsequent items smashed together in ADDR2. I understand that this meets the ask, but it's a time bomb. | |
| Oct 26, 2016 at 4:55 | comment | added | user8017719 | This breaks if $in contain newlines even if $IN is quoted. And adds a trailing newline. | |
| Sep 19, 2015 at 13:59 | comment | added | chepner |
This is probably due to a bug involving IFS and here strings that was fixed in bash 4.3. Quoting $IN should fix it. (In theory, $IN is not subject to word splitting or globbing after it expands, meaning the quotes should be unnecessary. Even in 4.3, though, there's at least one bug remaining--reported and scheduled to be fixed--so quoting remains a good idea.)
|
|
| Sep 3, 2012 at 10:07 | comment | added | Luca Borrione |
-1 This is not working here (ubuntu 12.04). Adding echo "ADDR1 $ADDR1"\n echo "ADDR2 $ADDR2" to your snippet will output ADDR1 [email protected] [email protected]\nADDR2 (\n is newline)
|
|
| May 31, 2012 at 5:36 | comment | added | dubiousjim |
Consider using read -r ... to ensure that, for example, the two characters "\t" in the input end up as the same two characters in your variables (instead of a single tab char).
|
|
| Sep 13, 2010 at 20:10 | history | answered | Darron | CC BY-SA 2.5 |