[Top][All Lists]

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

Re: Using "m4_bpatsubst/patsubst" to remove a string from a variable

From: Zack Weinberg
Subject: Re: Using "m4_bpatsubst/patsubst" to remove a string from a variable
Date: Mon, 6 Jun 2016 15:09:38 -0400

On Mon, Jun 6, 2016 at 2:21 PM, Eric Blake <address@hidden> wrote:
> On 06/06/2016 07:31 AM, Zack Weinberg wrote:
>> VAR2="`AS_ECHO("$VAR") | sed 's/text1//g'`"
> Correct in a POSIX shell, but liable to misbehave on some older shells.
> Better is:
> VAR2=`AS_ECHO("$VAR") | sed 's/text1//g'`
> Since it is in assignment context, you don't need the outer "" to
> prevent word splitting, the `` is enough for the shell to know where the
> assignment ends.

I am under the impression that there did once exist shells for which
the outer quotes *were* necessary to prevent word splitting (and
therefore misinterpretation of the overall statement as a
single-command environment variable override).  I am also under the
impression that any shell new enough to implement $() will *not* do
word splitting in a variable assignment.

Both of these factoids come out of the same "bitter experience with
vendor /bin/sh circa 1996" box in my head, so they may be totally
wrong, or they may only apply to shells sufficiently ancient as to be
irrelevant nowadays -- does anyone know for sure?


reply via email to

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