Thread (1 message) 1 message, 1 author, 2024-07-22

Re: [PATCH 1/2] t3701: avoid one-shot export for shell functions

From: Junio C Hamano <hidden>
Date: 2024-07-22 23:57:13

Junio C Hamano [off-list ref] writes:
Rubén Justo [off-list ref] writes:
quoted
The common construct:

    VAR=VAL command args

it's a common way to define one-shot variables within the scope of
executing a "command".
"it's a" -> "is a".
"define" -> "set and export".
quoted
However, when "command" is a function which in turn executes the
"command", the behavior varies depending on the shell:

 ** Bash 5.2.21 **

    $ f () { bash -c 'echo A=$A'; }
    $ A=1 f
    A=1

 ** dash 0.5.12-9 **

    $ f () { bash -c 'echo A=$A'; }
    $ A=1 f
    A=1

 ** dash 0.5.10.2-6 **

    $ f () { bash -c 'echo A=$A'; }
    $ A=1 f
    A=
Another thing.  Let's insert a paragraph perhaps like this here.

    Note that POSIX explicitly says the effect of this construct
    used on a shell function is unspecified.
quoted
One of our CI jobs on GitHub Actions uses Ubuntu 20.04 running dash
0.5.10.2-6, so we failed the test t3701:51;  the "git add -p" being
tested did not get our custom GIT_PAGER, which broke the test.

Work it around by explicitly exporting the variable in a subshell.
That way, we won't give a wrong impression that we can safely start
using the construct in future once dash 0.5.10.2-6 goes away.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help