All of lore.kernel.org
 help / color / mirror / Atom feed
* incomplete documentation of local?
@ 2022-11-20  4:57 Christoph Anton Mitterer
  2022-11-20  5:16 ` Christoph Anton Mitterer
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Anton Mitterer @ 2022-11-20  4:57 UTC (permalink / raw)
  To: dash

Hey.

I noticed two things in dash’s "local" which seem to be missing from
dash’s manpage:


1) Like bash’s, dash’s local seem to support:
   local foo=bar
   which doesn't seem to be mentioned in the manpage.

   I guess many people nevertheless use this (with dash), so it should
   either be documented as working, or as something one cannot rely on
   in the future.


2) There is no clear documentation about "local"’s exit status.
   The section describing it doesn’t say anything and it doesn’t seem
   to follow from other sections, e.g. "Command Exit Status" says
   merely:
   > Additionally, the builtin commands return exit
   > codes, as does an executed shell function.

   This is especially important as dash’s local seems to do the
   something similar than e.g. bash’s, and return 0 unless used outside
   of a function or on some invalid variable name (e.g. "$").

   However, it does not fail, when called on a readonly variable.

   The main problem of this not being documented is IMO, that people
   may easily be tempted that:
     local foo="$(somecommmand)"
     rc="$?"
   works like:
     foo="$(somecommmand)"
     rc="$?"
   and gives back the exit status of somecommand, which it does not.


I could provide a patch with some wording if that helps.


Thanks,
Chris.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: incomplete documentation of local?
  2022-11-20  4:57 incomplete documentation of local? Christoph Anton Mitterer
@ 2022-11-20  5:16 ` Christoph Anton Mitterer
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Anton Mitterer @ 2022-11-20  5:16 UTC (permalink / raw)
  To: dash

Oh and this obviously also affects e.g. set -e:
$ set -e
$ foo=$(false)
  => exit

$ local foo=$(false)
  => NO exit

In principle that's already clear once it's documented what "local"
returns, but it may be a common miss-assumption, so not sure whether it
should be specifically mentioned.


Thanks,
Chris.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-20  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-20  4:57 incomplete documentation of local? Christoph Anton Mitterer
2022-11-20  5:16 ` Christoph Anton Mitterer

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.