Ben Aston
Ben Aston

Reputation: 55779

Running a process in the background as part of a longer script

Given the following bash script, I would like the second step (the http-server invocation) to be run in the background.

The following appears to create a background process before the grunt call completes successfully, which is unexpected.

grunt build && http-server ./dist/artifacts -p 11111 &

I want the grunt step to run to successful completion, and then for the http-server call to be made with it running in the background.

What am I doing wrong?

Upvotes: 1

Views: 45

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74695

You can use { } around the part that you would like to be backgrounded:

grunt build && { http-server ./dist/artifacts -p 11111 & }

The curly braces create a block around the command after the &&, which means that the the & only backgrounds this part.

There is more about using { } for this purpose in the advanced bash scripting guide.

Upvotes: 3

Related Questions