Hi Mike,
Mike Jonkmans <[email protected]> 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