git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/8] git-prompt: don't use shell arrays

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 16, 2024, 12:38 UTC
Message-ID
<Zr9IWBRHBkcTwPZU@tanuki>
In-Reply-To
<701460728.4505561.1723808133505@mail.yahoo.com>
On Fri, Aug 16, 2024 at 11:35:33AM +0000, avih wrote:
Show 61 quoted lines
>  On Friday, August 16, 2024 at 01:52:11 PM GMT+3, Patrick Steinhardt <ps@pks.im> wrote:
> >On Fri, Aug 16, 2024 at 09:53:36AM +0000, avih wrote:
> >>  On Friday, August 16, 2024 at 11:50:14 AM GMT+3, Patrick Steinhardt <ps@pks.im> wrote:
> >> > On Thu, Aug 15, 2024 at 01:14:08PM +0000, Avi Halachmi (:avih) via GitGitGadget wrote:
> >> >>
> >> >> -            svn_remote[$((${#svn_remote[@]} + 1))]="$value"
> >> >> +            svn_remotes=${svn_remotes}${value}${LF}  # URI\nURI\n...
> >> >
> >> >
> >> > I was wondering whether this is something we want to quote, mostly
> >> > because I still have the failures of dash in mind when assigning values
> >> > with spaces to a `local` variable without quoting. I do not know whether
> >> > the same issues also apply to non-local variables though, probably not.
> >>
> >> IFS field splitting and glob expansion strictly never happen and never
> >> happened at the assignment part of a "simple command", since the first
> >> version of POSIX in 1994, so quotes are not needed to avoid that.
> >
> > That's the theory, yes. But as said, we did hit bugs in similar areas in
> > dash where that wasn't properly honored, as Junio also pointed out on a
> > later patch. But that was in non-POSIX area anyway, as to the best of my
> > knowledge it only happens with `local` assignments.
> 
> Yes. "local" is special, and not only because it's not POSIX.
> 
> The difference with "local" is that it takes assignment as arguments.
> 
> A "simple command" (posix term) is composed of optional assignment[s]
> and optional command (and arguments).
> 
> The assigments part is never IFS-split or glob-expanded, while the
> command and arguments part is (in words which include unquoted
> expansion or substitution) and therefore needs quotes, e.g.:
> 
> foo=$x bar=$y echo a="$b" c="$d"
> 
> There are other commands (beyond "local") which take assignment[s]
> as arguments, like "export", "readonly" and "command".
> 
> Before posix 2024, these commands also required quoting of the
> arguments-assignments - just like "local" needed in dash.
> 
> But posix 2024 introduced the concept of a "declaration utility"
> (which takes assignments as arguments, like export, readonly, etc),
> and the concept of "assignment context" where IFS-split and glob
> expansion don't happen - like the assignment part of a simple
> command, but now also in the assignment arguments of declaration
> utilities.
> 
> And indeed, new versions of shells now don't need quotes in export
> etc, and shells now make "local" a declaration utility which
> doesn't need quotes of the assignment args, including in dash.
> 
> However, the reason we do use quotes in local, export, etc, is
> because many instances of shells which don't yet (or will ever)
> support it still exist, so we quote for compatibility with those,
> but still it's only needed in assignments which are arguments to
> commands - not in the assignment part of a simple command.
> 
> I've also updated the wording a bit of my guidelines in part 5/8,
> and I'll include it at the commit message of 5/8 v3.
Great, thanks for your thorough explanations!
Patrick
Previous: avihNext: Avi Halachmi (:avih) via GitGitGadget
Message 39 of 80 in “git-prompt: support more shells”
  1. 0/8 git-prompt: support more shellsAvi Halachmi via GitGitGadget, Jul 23, 2024
  2. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  3. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  4. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  5. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  6. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  7. Junio C HamanoJul 23, 2024
  8. avihJul 24, 2024
  9. 6/8 git-prompt: add fallback for shells without $'...'Avi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  10. Junio C HamanoJul 23, 2024
  11. avihJul 24, 2024
  12. avihJul 25, 2024
  13. avihJul 25, 2024
  14. Junio C HamanoJul 25, 2024
  15. avihJul 25, 2024
  16. Junio C HamanoJul 25, 2024
  17. avihAug 14, 2024
  18. Junio C HamanoAug 14, 2024
  19. avihAug 15, 2024
  20. Junio C HamanoAug 15, 2024
  21. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  22. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  23. brian m. carlsonJul 23, 2024
  24. avihJul 24, 2024
  25. Junio C HamanoJul 24, 2024
  26. Junio C HamanoJul 24, 2024
  27. avihJul 24, 2024
  28. 0/8 git-prompt: support more shells v2Avi Halachmi via GitGitGadget, Aug 15, 2024
  29. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  30. Patrick SteinhardtAug 16, 2024
  31. avihAug 16, 2024
  32. Patrick SteinhardtAug 16, 2024
  33. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  34. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  35. Patrick SteinhardtAug 16, 2024
  36. avihAug 16, 2024
  37. Patrick SteinhardtAug 16, 2024
  38. avihAug 16, 2024
  39. Patrick SteinhardtAug 16, 2024
  40. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  41. Junio C HamanoAug 15, 2024
  42. avihAug 16, 2024
  43. Junio C HamanoAug 16, 2024
  44. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  45. Junio C HamanoAug 15, 2024
  46. avihAug 15, 2024
  47. Junio C HamanoAug 15, 2024
  48. avihAug 15, 2024
  49. 6/8 git-prompt: don't use shell $'...'Avi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  50. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  51. Patrick SteinhardtAug 16, 2024
  52. avihAug 16, 2024
  53. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  54. Junio C HamanoAug 15, 2024
  55. Patrick SteinhardtAug 16, 2024
  56. 0/8 git-prompt: support more shells v3Avi Halachmi via GitGitGadget, Aug 17, 2024
  57. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  58. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  59. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  60. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  61. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  62. Eric SunshineAug 17, 2024
  63. avihAug 17, 2024
  64. Junio C HamanoAug 17, 2024
  65. avihAug 17, 2024
  66. 6/8 git-prompt: don't use shell $'...'Avi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  67. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  68. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  69. 0/8 git-prompt: support more shells v4Avi Halachmi via GitGitGadget, Aug 20, 2024
  70. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  71. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  72. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  73. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  74. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  75. 6/8 git-prompt: don't use shell $'...'Avi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  76. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  77. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  78. Junio C HamanoAug 20, 2024
  79. avihAug 20, 2024
  80. avihAug 28, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.