Manage ctrl+z and bg or & signal in shell script - (background process in shell script)

I have an script that holds inside:

cd $1
ng s --host 0.0.0.0 --port 4200
...another commands ... 

so, i want to run an angular project inside that. I'm executting the script from a micro-service so actually that service never gives me back response because of the ng s command's behavior. enter image description here

Keeping that in mind, i want to execute the "ng s ..." command in background, but when i run:

ng s --host 0.0.0.0 --port 4200 &

the ng s takes the & as invalid argument. I mean, i tried to run the script in background several ways with no luck

How can i achieve that?

Upvotes: 0

Views: 320

Answers (1)

riverfall
riverfall

Reputation: 840

As an option, you can write down a short bash script which contains only

#!/bin/bash
ng s --host 0.0.0.0 --port 4200

and then start it as

script.sh &

or if you want to keep it running after disconnecting from the terminal:

nohup script.sh &

Upvotes: 2

Related Questions