help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: split a string into an array?


From: Koichi Murase
Subject: Re: split a string into an array?
Date: Fri, 11 Mar 2022 16:24:36 +0900

2022年3月11日(金) 14:32 Kerin Millar <kfm@plushkava.net>:
> The problem with this is that the same word splitting behavioural issues that 
> would also apply to read then come into play. For instance:
>
> $ set -f
> $ sep=$'\t' input=$'foo\t\t\tbar\t'
> $ IFS=$sep builtin eval 'array=($input${input:+$sep})'
> $ declare -p array
> declare -a array=([0]="foo" [1]="bar")

Ah, thank you for the information. I have been somehow wrongly
thinking that this special treatment would only happen when IFS has
the default value. I think I was confused by the description in "man
bash" about the treatment of the consecutive whitespaces at the
beginning and the ending of the string. I haven't noticed this
behavior so far since I usually use ":", ",", etc. as the delimiter
for my codes.

--
Koichi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]