http://stackoverflow.com/q/21517281
This command succeeds
$ PS1='$(date +%s) $ '
1391380852 $
However if I add a newline it fails
$ PS1='$(date +%s)\n$ '
bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `date +%s)'
If I use backticks it works
$ PS1='`date +%s`\n$ '
1391381008
$
but backticks are discouraged. So what is causing this error?
I'm running into the same thing when trying to use the git-prompt in MSYS2.
The exact same prompt is working fine on another machine running Arch Linux, which also happens to be using the same version of bash (4.3.22).
If I remove the newline after the command substitution, it works.
It seems like $() style command substitution for some reason always fails in MSYS2 if a newline is present after it.
Here my own PS1 that works:
It's hard to read but it works. I derive this using the answer provided in the stack overflow question above.
I don't know why it is not working as expected however.
Regards,
Matt
Putting any newlines after the command substitution in its own quotes with a dollar sign in front of it does indeed avoid the error, as does using backticks.
Still seems odd that this is necessary when the same thing works fine on other platforms though.
I tried your PS1, but I still get this error:
bash: __git_ps1: command not found
Any ideas? I just installed msys2 on Windows 8.1 today so I'm not very familiar with it.
UPDATE: Fixed it by copying in git-prompt.sh and git-completion.bash files from msysgit to my /etc folder and adding the following to my .profile:
. /etc/git-completion.bash
[ -r /etc/git-prompt.sh ] && . /etc/git-prompt.sh
Last edit: Andreas Larsen 2014-11-05
I was about to reply exactly this. Glad you solved your problem.
Regards,
Matt
Huh, seems to work now. Closing.
And now it doesn't. Opening. :/