Dash Archive mirror
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: dash@vger.kernel.org
Subject: [BUG] one-shot variables aren't propagated past functions
Date: Thu, 30 Apr 2020 06:00:01 -0400	[thread overview]
Message-ID: <20200430100001.GA30093@generichostname> (raw)

Hi all,

I believe that I've encountered a bug in dash 0.5.10.2. With the
following input
	
	f () {
		echo $var
	}

	var=test f
	echo $var

I would expect the output to be
	
	test
	test

but the output is actually

	test
	<blank>

It seems like this violates the POSIX spec. Quoting Junio C Hamano[1]:
> Johannes Sixt <j.sixt@viscovery.net> writes:
> 
> > Tarmigan Casebolt schrieb:
> >>         REQUEST_METHOD="GET" some_shell_function
> >
> >> I can't tell from my reading of the POSIX spec whether my usage was
> >> wrong or if dash is wrong,
> >
> > According to POSIX, variables set as shown above for shell functions are
> > not exported and retain their value after the function returns.
> 
> I actually looked for this yesterday, but didn't find a relevant
> definition.  But "2.9.5 Function Definition Command" [*1*] seems to
> address the issue: "When a function is executed, it shall have the
> syntax-error and variable-assignment properties described for special
> built-in utilities...".
> 
> And "2.14 Special Built-in Utilities" section [*2*] says "2. Variable
> assignments specified with special built-in utilities remain in effect
> after the built-in completes...".  Taking both together, it seems that
> the assignment should be in effect after the function returns.
> 
[...]
> 
> [References]
> 
> *1* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_05
> *2* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_14

It also seems like on bash 5.0.16, running with --posix produces the
expected output, although without --posix it produces the blank line.

Originally discussed here[2].

Thanks,

Denton

[1]: https://lore.kernel.org/git/7vljfzz0yd.fsf@alter.siamese.dyndns.org/
[2]: https://lore.kernel.org/git/20200430092220.GA25331@generichostname/

             reply	other threads:[~2020-04-30 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 10:00 Denton Liu [this message]
2020-04-30 15:12 ` [BUG] one-shot variables aren't propagated past functions Michael Greenberg

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=20200430100001.GA30093@generichostname \
    --to=liu.denton@gmail.com \
    --cc=dash@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).