Jose Bustillo
Jose Bustillo

Reputation: 21

Why does terminal stop after run "bash" in a .bat file (WSL) and how to run it properly?

I would like to automatize a process running a .bat file but using the bash terminal in my WSL2. These are my commands in my .bat:

bash
cd ~/Dev/Folder
nvm use 14.15.0
npm start

But the .bat stops after running "bash". I also tried with bash && cd ~/Dev/Folder && nvm use 14.15.0 && npm start and also replacing "bash" with "wsl", but same result.

Image of the result

Maybe I'm doing something wrong, so I would appreciate some help with this.

Upvotes: 1

Views: 296

Answers (1)

ForceBru
ForceBru

Reputation: 44868

bash starts a new Bash shell and waits for it to exit, like for any other terminal command. The subsequent commands are not redirected to Bash - they'll be executed once the Bash process exits.

To run commands within Bash, use the -c flag:

bash -c "cd ~/Dev/Folder && ls && nvm use 14.15.0 && npm start"

Also see What does 'bash -c' do?.

Upvotes: 4

Related Questions