Timeline for How to split one string into multiple variables in bash shell?
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 10, 2016 at 13:57 | comment | added | Rob I | You're right about double quotes of course, though I did point out this solution wasn't general. However I think your assessment is a bit unfair - for some people this solution may be more readable (and hence extensible etc) than some others, and doesn't completely rely on arcane bash feature that wouldn't translate to other shells. I suspect that's why my solution, though less elegant, continues to get votes periodically... | |
Jan 25, 2016 at 6:47 | comment | added | tripleee |
Apart from being an ugly last-resort solution, this has a bug: You should absolutely use double quotes in echo "$STR" unless you specifically want the shell to expand any wildcards in the string as a side effect. See also stackoverflow.com/questions/10067266/…
|
|
Nov 27, 2012 at 10:26 | comment | added | FSp | Although this is very simple to read and write, is a very slow solution because forces you to read twice the same data ($STR) ... if you care of your script performace, the @anubhava solution is much better | |
May 9, 2012 at 17:59 | comment | added | Matt K |
You can use cut to cut characters too! cut -c1 for example.
|
|
May 9, 2012 at 17:40 | comment | added | crunchybutternut | Can you look at my post again and see if you have a solution for the followup question? thanks! | |
May 9, 2012 at 17:10 | vote | accept | crunchybutternut | ||
May 9, 2012 at 17:00 | history | answered | Rob I | CC BY-SA 3.0 |