Timeline for How to split one string into multiple variables in bash shell?
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 28, 2022 at 13:19 | comment | added | Dennis Williamson | @JerryGreen: How does it not work with Bash 3 in MacOS? I'm not seeing a difference. | |
Jun 28, 2022 at 13:17 | history | edited | Dennis Williamson | CC BY-SA 4.0 |
mac sed doesn't support \v escape, let bash create it
|
Jun 24, 2022 at 0:14 | comment | added | Dennis Williamson |
@akwky: Use an alternate file descriptor. while read -r line <&3; do ssh_or_something "$line"; done 3<file
|
|
Jun 24, 2022 at 0:07 | history | edited | Dennis Williamson | CC BY-SA 4.0 |
added -r
|
Jan 21, 2022 at 10:22 | comment | added | Fravadona |
A more general, correct, way: IFS=- read -r -d '' var1 var2 < <(printf %s "ABCDE-123456") . The -r -d '' and <(printf %s ...) are important
|
|
S Dec 12, 2021 at 17:36 | history | suggested | CervEd | CC BY-SA 4.0 |
clarify - is the separator
|
Dec 10, 2021 at 10:30 | review | Suggested edits | |||
S Dec 12, 2021 at 17:36 | |||||
Nov 11, 2020 at 14:30 | comment | added | Jerry Green | I initially gave this answer a plus as an elegant solution, but now figured out it works differently on Bash v3 and v4, thereby doesn't work on macos with pre-installed bash v3. Unfortunatelly I can't downvote the answer now since the vote is locked :( | |
Feb 24, 2020 at 10:59 | comment | added | akwky |
The read does not work inside loops with input redirects. read will pick a wrong file descriptor to read from.
|
|
Jan 11, 2018 at 4:34 | comment | added | Martin Serrano |
this solution also has the benefit that if delimiter is not present, the var2 will be empty
|
|
Jul 4, 2012 at 16:14 | history | edited | Dennis Williamson | CC BY-SA 3.0 |
additional information; added 259 characters in body
|
May 10, 2012 at 3:14 | history | answered | Dennis Williamson | CC BY-SA 3.0 |