[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug? {1..3} doesnt' use IFS to separate fields
From: |
Geir Hauge |
Subject: |
Re: bug? {1..3} doesnt' use IFS to separate fields |
Date: |
Wed, 27 Jul 2011 11:53:49 +0200 |
2011/7/25 Linda Walsh <address@hidden>
>
>
> I know it wasn't designed this way, but it seems like it
> is a bug.
>
The manual says nothing about brace expansion using IFS in any way, so it's
not a bug.
If I do
> read a b c <<<$(echo {1..3} ); echo "a:$a b:$b c:$c"
> I get:
> a:1 b:2 c:3
>
> But If I do
> export IFS=','; read a b c <<<$(echo {1..3} ); echo "a:$a b:$b c:$c"
> I get:
> a:1 2 3 b: c:
>
> Why should the 2nd case return the wrong answer?
> I.e. shouldn't {1..3} use the IFS to separate arguments?
>
I don't see the usefulness in having brace expansion's behavior changed by
IFS.
If you want {1..3} to turn into the string "1;2;3", assign it to an array,
then print the array that way
array=( {1..3} )
(IFS=';'; echo "${array[*]}") # outputs "1;2;3"
printf -v var '%s;' "address@hidden"; echo "$var" # outputs "1;2;3;"
--
Geir Hauge