word 1$ od -bc <<< "$IFS"
that and
ANother string
Foo on you!!!
In earlier episodes of our saga, I had complained about the lack of a
"split" function in bash. By "split", I mean taking a string and making an >array out of it, as does the AWK "split" function.
In earlier episodes of our saga, I had complained about the lack of a
"split" function in bash. By "split", I mean taking a string and making an array out of it, as does the AWK "split" function.
I have now figured out a general solution to this problem. Observe:
The idea does not originate with Prakash. The following 2019-dated StackOverflow answer documents the approach also.
https://stackoverflow.com/a/58600824/1250772
In article <sis9e1$2konq$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
In earlier episodes of our saga, I had complained about the lack of a >>"split" function in bash. By "split", I mean taking a string and making an >>array out of it, as does the AWK "split" function.
Note that this same general idea can be used to address another question
that I've wrestled with (and posted about) previously: That is, removing leading/trailing blanks from a string in bash. Observe:
$ foo=" leading and trailing spaces "
$ read -r bar <<< "$foo"
In fact, you could even do:
$ read -r foo <<< "$foo"
to do it "in place".
On Mon, 27 Sep 2021 14:45:32 +0000, Kenny McCormack wrote:Typo
In article <sis9e1$2konq$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
In earlier episodes of our saga, I had complained about the lack of a >>>"split" function in bash. By "split", I mean taking a string and making an >>>array out of it, as does the AWK "split" function.
Note that this same general idea can be used to address another question
that I've wrestled with (and posted about) previously: That is, removing
leading/trailing blanks from a string in bash. Observe:
$ foo=" leading and trailing spaces "
$ read -r bar <<< "$foo"
In fact, you could even do:
$ read -r foo <<< "$foo"
to do it "in place".
I suggest that even the "read" is redundant
foo=" leading and trailing spaces "
bar=( $foo }
And, of course, it works with an altered IFS
oldIFS=$IFS
IFS=e bar=$($foo)
IFS=$oldIFS
In article <20210927084957.715@kylheku.com>,
Kaz Kylheku <480-992-1380@kylheku.com> wrote:
On 2021-09-27, Kenny McCormack <gazelle@shell.xmission.com> wrote:
In earlier episodes of our saga, I had complained about the lack of a
"split" function in bash. By "split", I mean taking a string and making an >>> array out of it, as does the AWK "split" function.
I have now figured out a general solution to this problem. Observe:
You were beaten to it by days by one Abhishek Prakash, who blogged about
it on September 4. It comes up as the first hit in a search for "split
string into array in bash" in ducu
What makes you think I read any of those websites (Stack*, LinuxWhatever, ...) ?
On 2021-09-27, Kenny McCormack <gazelle@shell.xmission.com> wrote:
In earlier episodes of our saga, I had complained about the lack of a
"split" function in bash. By "split", I mean taking a string and making an >> array out of it, as does the AWK "split" function.
I have now figured out a general solution to this problem. Observe:
You were beaten to it by days by one Abhishek Prakash, who blogged about
it on September 4. It comes up as the first hit in a search for "split >string into array in bash" in ducu
Stil blows goats, but its nice not having to save, assign and
restore IFS, at least.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 185 |
Nodes: | 16 (1 / 15) |
Uptime: | 56:50:42 |
Calls: | 3,747 |
Files: | 11,167 |
Messages: | 3,458,006 |