I'm writing a cross-platform nodejs script that executes bash commands. It should work the same way on Linux/MacOS/Windows, but on my Windows machine with Git Bash there seems to be an issue with escape sequences.
While trying out the child_process.spawn function, I encountered a strange behavior that I was able to reproduce in Windows cmd.exe:
d:\>bash -c "echo $'this is \a test'"
this is test
d:\>bash -c "echo $'this is \\a test'"
this is test
The first output is expected, but in the second it looks like \\a is treated as the \a escape sequence.
Running the same commands in an interactive bash session yields correct results:
$ echo $'this is \a test'
this is test
$ echo $'this is \\a test'
this is \a test
Setup
Details
I'm writing a cross-platform nodejs script that executes bash commands. It should work the same way on Linux/MacOS/Windows, but on my Windows machine with Git Bash there seems to be an issue with escape sequences.
While trying out the child_process.spawn function, I encountered a strange behavior that I was able to reproduce in Windows cmd.exe:
The first output is expected, but in the second it looks like
\\a
is treated as the\a
escape sequence.Running the same commands in an interactive bash session yields correct results: