coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH v2] printenv,env: quote problematic variables


From: Collin Funk
Subject: Re: [PATCH v2] printenv,env: quote problematic variables
Date: Mon, 31 Aug 2026 19:06:24 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Mike,

Mike Jonkmans <coreutils@jonkmans.nl> writes:

> On Sun, Aug 30, 2026 at 07:14:43PM -0700, Collin Funk wrote:
>> AFAIK,
>> sudo only allows you to preserve the entire environment or specific
>> variables. I.e., there is no way to set a variable to a given value.
>
> Hi Collin,
>
> Would the --preserve-env option be of any help?
>
> TERM=xterm X1=4 X2=2 NOT=no \
>       sudo --preserve-env=X1,X2 sh -c 'echo $TERM $X1$X2 $NOT'

I should have been more clear with my mail, sorry. Here we are more-so
concerned with the setting of the variables from the output of
'printenv'.

So when you use:

    $ export VAR=$(printf 'a\nb')
    $ printenv VAR
    'a'$'\n''b'
    $ NEW_VAR="$(printenv TAB)"
    $ echo "$VAR" | od -c
    0000000   a  \n   b  \n
    0000004

You wouldn't want $NEW_VAR to contain all of that extra quoting and
such. Instead it should just be the literal value "a\nb" where that is
an actual newline.

My original patch made that the case, but PƔdraig was rightfully
concerned about it.

Thanks for the response anyways.

Collin




reply via email to

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