public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* bash: '\n' after command substitution in $PS1 causes errors when igncr is set
@ 2024-05-23  4:16 Ken Takata
  0 siblings, 0 replies; only message in thread
From: Ken Takata @ 2024-05-23  4:16 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 752 bytes --]

Hello all,

I originally reported this issue to the msys2 team:
https://github.com/msys2/MSYS2-packages/issues/1839
https://github.com/msys2/MSYS2-packages/pull/4477
But I find that this issue is coming from Cygwin Bash, so I'm reporting
here.

When I use \n after command substitution in $PS1, it causes syntax errors
when the igncr option is set:
```
$ set -o igncr
$ PS1='$(date)\n\$ '
-bash: command substitution: line 1: syntax error near unexpected token `)'
-bash: command substitution: line 1: `date)'
```
(Confirmed with bash-5.2.21-1)

I found an issue in rewind_input_string() in parse.y. It didn't take care
of '\r'.
Please find the attached patch to fix it.
Could you consider merging this into bash-5.2-cygwin.patch?

Regards,
Ken Takata

[-- Attachment #2: bash-5.2-cygwin-fix-igncr.patch --]
[-- Type: application/octet-stream, Size: 534 bytes --]

--- a/parse.y
+++ b/parse.y
@@ -1684,7 +1684,16 @@
      into account, e.g., $(...\n) */
   xchars = shell_input_line_len - shell_input_line_index;
   if (bash_input.location.string[-1] == '\n')
-    xchars++;
+    {
+      xchars++;
+#ifdef __CYGWIN__
+      {
+	extern int igncr;
+	if (igncr && bash_input.location.string[-2] == '\r')
+	  xchars++;
+      }
+#endif
+    }
 
   /* XXX - how to reflect bash_input.location.string back to string passed to
      parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-23  4:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-23  4:16 bash: '\n' after command substitution in $PS1 causes errors when igncr is set Ken Takata

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).