bug-bash
[Top][All Lists]
Advanced

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

Re: RFC: turn off word splitting for vars but keep for read


From: Aleksey Midenkov
Subject: Re: RFC: turn off word splitting for vars but keep for read
Date: Fri, 22 Nov 2013 21:36:13 +0400

On Fri, Nov 22, 2013 at 7:07 PM, Pierre Gaston <address@hidden> wrote:
>
>
>
> On Fri, Nov 22, 2013 at 8:00 AM, Aleksey Midenkov <address@hidden> wrote:
>>
>> Since word splitting in vars is used not more frequently than never,
>> protecting all vars in scripts with double quotes is quite unpleasant
>> thing. Therefore, I want exactly this behavior always to be in my
>> scripts:
>>
>> $ IFS=""
>> $ f() { echo $1; }; x="a b c"; f $x
>> a b c
>>
>> But, IFS influences `read`, which of course benefits from word
>> splitting. In light of that conflict, I propose two possible
>> solutions:
>>
>> 1: shopt -s unsplit_vars
>>
>> which will turn off word splitting for var expansion.
>>
>> or 2: new IFS2 var that will override IFS for `read` (i.e. `read` will
>> use IFS2 when IFS is unset).
>
>
> Your code is still not safe, you would need set -f to disable globing too.
>
> it's easy enough to set IFS locally for read, just set it in its environment
> like
> IFS=' ' read a b <<"hello world"
>

Yes, I know, I'd ever done alias for `read`:

IFS=""
shopt -s expand_aliases
alias read='IFS=" " read'

But nevertheless, I still find my proposal usable (since word
splitting for vars is unlikely to be usable in scripts).



reply via email to

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