[Top][All Lists]

[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: Eduardo A . Bustamante López
Subject: Re: RFC: turn off word splitting for vars but keep for read
Date: Fri, 22 Nov 2013 11:13:53 -0800
User-agent: Mutt/1.5.21 (2010-09-15)

> Yes, I know, I'd ever done alias for `read`:
> IFS=""
> shopt -s expand_aliases
> alias read='IFS=" " read'
Why do you obfuscate your code with aliases? These just make
debugging issues with your code harder. Remembering to quote
variables and use a localized IFS for read is easier, than
introducing an incompatible behaviour that will just help to make the
confusion of shell scripting bigger.

When giving support, it's easier to tell people: «Just double quote
every parameter expansion when you're in doubt», than to list all the
possible cases where they should and shouldn't. With your proposal,
you're just adding a new variable to the mess...

> But nevertheless, I still find my proposal usable (since word
> splitting for vars is unlikely to be usable in scripts).
Word splitting *IS* being used actively in lots of shell scripts that
aim for POSIX compatibility (because it's the only way of
pseudo-emulating arrays), and even it's used (wrongly) in bash
scripts that do not aim to be compatible with the POSIX shell.

So, if the user puts your shopt in ~/.bashrc and happens to run a
script that relies on that... breakage.

Also, lazyness is not a justification. Shell scripts are written
once, but read and executed many times, so invest a little time into
quoting properly, instead of relying on a modified IFS and set -f. Or
use a language that doesn't have to be compatible with POSIX sh.

Quoting isn't that hard once you get used to it ;)

Eduardo Alan Bustamante López

reply via email to

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