Amit
Amit

Reputation: 83

Git Bash error in VS code unexpected token '&'

I'm a beginner and I'm getting a bash syntax error Unexpected token '&'

Initially, I was getting this error while using a virtual environment in python. But today I cleaned my PC and reinstalled the window and now I can't even run normal programs.

Cause of Error -> I'm using VS Code and terminal as Git Bash.

After wasting days I got to know that this is happening because Bash and PowerShell have different syntax and when I'm running the code the vs code is not adapting to bash's syntax (and yes it works on PowerShell).

And Default terminal is also set to Git Bash in my JSON setting file like this: "terminal.integrated.defaultProfile.windows": "Git Bash",

I tried changing to another famous way: "terminal.integrated.shell.windows":"path_here" and it does not work either and says deprecated method.

How can I change the default Syntax of vs code terminal? Do I have to reinstall the bash and change something in my options? And I was using bash b4 as well but never faced this issue but then I recently started using virtual env then this error occurred for the first time. So I'm confused whether this is an in-built problem or something that I can fix? And I found many ppl with the same type of question (which are posted recently that leads me to think it could be a fault from their side) in StackOverflow but no one was able to define it hence I'm adding this one.

Upvotes: 1

Views: 1527

Answers (2)

Amit
Amit

Reputation: 83

Yes, i was right. The issue was in the VScode itself. Today there was an update and everything seems to be normal/working now.

Upvotes: 1

VonC
VonC

Reputation: 1329032

But today I cleaned my pc and reinstalled the window and now i can't even run normal programs.

Make sure your %PATH% environment variable does include C:\Program Files\Git\bin\ in order to know about bash.exe

Try and launch, for testing, VSCode after setting the PATH in a CMD with:

set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%

rem Then, in the same CMD
"%LOCALAPPDATA%\Programs\Microsoft VS Code\bin\code.cmd"

Upvotes: 0

Related Questions