From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] CodingGuidelines: document a shell that "fails" "VAR=VAL shell_func"
Date: Tue, 23 Jul 2024 08:28:27 -0700 [thread overview]
Message-ID: <xmqqfrs03z6s.fsf@gitster.g> (raw)
In-Reply-To: <20240723033418.GA1838963@coredump.intra.peff.net> (Jeff King's message of "Mon, 22 Jul 2024 23:34:18 -0400")
Jeff King <peff@peff.net> writes:
> On Mon, Jul 22, 2024 at 04:10:41PM -0700, Junio C Hamano wrote:
>
>> Over the years, we accumulated the community wisdom to avoid the
>> common "one-short export" construct for shell functions, but seem to
>> have lost on which exact platform it is known to fail. Now during
>> an investigation on a breakage for a recent topic, we found one
>> example of failing shell. Let's document that.
>
> My recollection was that FreeBSD's /bin/sh was the culprit, but I
> couldn't find any mention digging in the archive. However, I just
> checked on a FreeBSD 13 VM, and it does have the same problem (that the
> one-shot variable is not exported). I don't think that changes anything
> for your patch, but just reinforces this part:
>
>> This does *not* mean that we can freely start using the construct
>> once Ubuntu 20.04 is retired. But it does mean that we cannot use
>> the construct until Ubuntu 20.04 is fully retired from the machines
>> that matter.
>
> since now we have one other instance.
>
> I thought it also had the issue that the variable would remain set in
> the caller after the function returned, but it does not seem to do so
> now (if it ever did).
Yeah, that one is also what POSIX leaves to the implementation, if I
recall what I read there.
So here is how the part looks like in my tree right now.
Thanks.
diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines
index 2151ec51b8..52afb2725f 100644
--- c/Documentation/CodingGuidelines
+++ w/Documentation/CodingGuidelines
@@ -212,11 +212,11 @@ For shell scripts specifically (not exhaustive):
"command args" is running is handy, but this triggers an
unspecified behaviour according to POSIX when used for a command
that is not an external command (like shell functions). Indeed,
- some versions of dash (like 0.5.10.2-6 found on Ubuntu 20.04) and
- AT&T ksh do make a temporary assignment without exporting the
- variable, in such a case. Do not use it for shell functions. A
- common workaround is to do an explicit export in a subshell, like
- so:
+ dash 0.5.10.2-6 on Ubuntu 20.04, /bin/sh on FreeBSD 13, and AT&T
+ ksh all make a temporary assignment without exporting the variable,
+ in such a case. As it does not work portably across shells, do not
+ use this syntax for shell functions. A common workaround is to do
+ an explicit export in a subshell, like so:
(incorrect)
VAR=VAL func args
next prev parent reply other threads:[~2024-07-23 15:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 23:10 [PATCH v2] CodingGuidelines: document a shell that "fails" "VAR=VAL shell_func" Junio C Hamano
2024-07-23 0:04 ` [PATCH v3] " Junio C Hamano
2024-07-23 0:10 ` Eric Sunshine
2024-07-23 0:23 ` Junio C Hamano
2024-07-23 3:34 ` [PATCH v2] " Jeff King
2024-07-23 15:28 ` Junio C Hamano [this message]
2024-07-23 21:55 ` Rubén Justo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqfrs03z6s.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.