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: Sat, 23 Nov 2013 00:20:41 +0400

On Fri, Nov 22, 2013 at 11:21 PM, Pierre Gaston <address@hidden> wrote:
>
>
>
> On Fri, Nov 22, 2013 at 8:53 PM, Eric Blake <address@hidden> wrote:
>>
>> On 11/22/2013 10:36 AM, Aleksey Midenkov wrote:
>>
>> > But nevertheless, I still find my proposal usable (since word
>> > splitting for vars is unlikely to be usable in scripts).
>>
>> Scripts use word splitting on variables ALL the time.  For example, I
>> bet you have (multiple copies of) a script named install-sh somewhere on
>> your system.  It frequently uses word split variables, such as these
>> setup lines:
>>
>> rmprog=${RMPROG-rm}
>> ...
>> rmcmd="$rmprog -f"
>>
>> for use in constructs like this:
>>           $doit $rmcmd -f "$dst" 2>/dev/null ||
>>
>> Disabling word splitting for an interactive shell is one thing (and in
>> fact, zsh has done that in their default mode), but for scripting, you
>> would break LOTS of existing scripts if you changed the default behavior
>> of word splitting.
>>
>> --
>> Eric Blake   eblake redhat com    +1-919-301-3266
>> Libvirt virtualization library http://libvirt.org
>>
> well, he proposes an option to turn on these behavior, not to change the
> default behaviour.
> I reckon something like shopt -s autoquote_expansions could be useful

Exactly. I need this option only for my scripts, not for all scripts.
shopt -s unsplit_vars will be shorter and more clear, IMHO.

I would say, that this style generally is wrong:

rmprog=${RMPROG-rm}
rmcmd="$rmprog -f"

Because it will fail for files with spaces. It is better (when don't
worry about portability and backward compatibility like in autotools)
to use array:

rmcmd=("$rmprog" -f)

and then: "address@hidden)"

But, these pesky double quotes we need to put everywhere because of
word splitting.



reply via email to

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