1

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.