Skip to content

Commit a7fa609

Browse files
sunshinecogitster
authored andcommitted
check-non-portable-shell: loosen one-shot assignment error message
When a0a6301 (t/check-non-portable-shell: detect "FOO=bar shell_func", 2018-07-13) added the check for one-shot environment variable assignment for shell functions, the primary reason given for avoiding them was that, under some shells, the assignment outlives the invocation of the shell function, thus could potentially negatively impact subsequent commands in the same test, as well as subsequent tests. However, it has recently become apparent that this is not the only potential problem with one-shot assignments and shell functions. Another problem is that some shells do not actually export the variable to commands which the function invokes[1]. More significantly, however, the behavior of one-shot assignments with shell functions is not specified by POSIX[2]. Given this new understanding, the presented error message ("assignment extends beyond 'shell_func'") is too specific and potentially misleading. Address this by emitting a less specific error message. (Note that the wording "is not portable" is chosen over the more specific "behavior not specified by POSIX" for consistency with almost all other error message issued by this "lint" script.) [1]: https://lore.kernel.org/git/[email protected]/ [2]: https://lore.kernel.org/git/[email protected]/ Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e91056 commit a7fa609

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

t/check-non-portable-shell.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ sub err {
5050
/\blocal\s+[A-Za-z0-9_]*=\$([A-Za-z0-9_{]|[(][^(])/ and
5151
err q(quote "$val" in 'local var=$val');
5252
/^\s*([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
53-
err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
53+
err '"FOO=bar shell_func" is not portable';
5454
$line = '';
5555
# this resets our $. for each file
5656
close ARGV if eof;

0 commit comments

Comments
 (0)