Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash: '\n' after command substitution in $PS1 causes error #1839

Open
k-takata opened this issue Jan 27, 2020 · 6 comments · May be fixed by #4477
Open

bash: '\n' after command substitution in $PS1 causes error #1839

k-takata opened this issue Jan 27, 2020 · 6 comments · May be fixed by #4477

Comments

@k-takata
Copy link
Contributor

When I use \n after command substitution in $PS1, it causes syntax error:

$ PS1='$(date)\n\$ '
-bash: command substitution: line 1: syntax error near unexpected token `)'
-bash: command substitution: line 1: `date)'

It should not cause the error.
If I remove the \n after $(date), it works fine:

$ PS1='$(date)\$ '
Mon Jan 27 19:16:55 JST 2020$ 

Using backquotes instead of $() also works fine:

$ PS1='`date`\n\$ '
Mon Jan 27 19:21:51 JST 2020
$ 

Setting PS1='$(date)\n\$ ' works fine on Cygwin, so this seems an MSYS2 specific issue.

See also: https://stackoverflow.com/questions/21517281/ps1-command-substitution-fails-when-containing-newlines-on-msys-bash

@k-takata
Copy link
Contributor Author

If I revert the following hunks, the issue disappears:

- return (*(bash_input.getter)) ();
+#ifdef __MSYS__
+ int c;
+ while ((c = (*(bash_input.getter)) ()) == '\r');
+ return c;
+#else
+ return (*(bash_input.getter)) ();
+#endif

- return (*(bash_input.getter)) ();
+#ifdef __MSYS__
+ int c;
+ while ((c = (*(bash_input.getter)) ()) == '\r');
+ return c;
+#else
+ return (*(bash_input.getter)) ();
+#endif

+#ifdef __MSYS__
+ if (c == '\r')
+ continue;
+#endif

@stirwl
Copy link

stirwl commented Jul 14, 2023

I have same issue too.
My bash version is 5.2.15(1)-release (x86_64-pc-msys)

@GeekDuanLian
Copy link

I recently switched from Cygwin to MSYS2 and I have the same problem, and this problem seems to be only on MSYS2, I don't experience it on any of the remaining platforms.

Hope this issue can be fixed soon.

@stirwl
Copy link

stirwl commented Oct 7, 2023

I add \e[0m\]\n at the line end. It works fine.

@akinomyoga
Copy link
Contributor

This hasn't yet been fixed after four years since the report. Did anyone make an effort to fix this problem? @lazka @Alexpux Who are responsible for the Bash package in MSYS2?

This causes many error reports as follows. This is not a complete list. These are just the reports to a repository that I maintain and some others that can be quickly found by Google search.

For individual personal setting, "the fix" suggested in some of the threads or #1839 (comment) might work. However, we don't want to include in a larger shared framework such specific workarounds caused by a package unmaintained for ten years unless there is a reason that this cannot be fixed in the origin.

@akinomyoga
Copy link
Contributor

@lazka Who is responsible for the Bash package?

@k-takata k-takata linked a pull request Mar 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants