edit: I got it, see bottom of this message.
tldr: In a git post-receive hook, I’m doing npx @11ty/eleventy &, with an ampersand at the end. Yet, when I git push, I still have to wait for the output of npx @11ty/eleventy to finish before I regain control of the terminal. Why is that? And how can I just tell it to continue without waiting for the npx to finish?
Longer question:
I have a website that is being generated by a static HTML generator (I’m using 11ty). I want the site to regenerate every time I push to a specific git repo, which is hosted on my web server. I’m using the post-receive git hook to do this.
If you aren’t familiar with git hooks, it’s basically a bash script that goes in the .git/hooks directory that will run every time specific things happen in your repo. You can check out the sample ones that are included by default in every repo: you’ve got post-commit, post-receive (for the server side), etc.
So I’m using a post-receive script on the server side to call the 11ty command and regenerate the site whenver I push a new commit. It works, and it’s very slick.
git will show you the output of the script whenever you push to the server. Which is also very cool, except that I’d rather not wait for that. This site will eventually get very large, so I’d rather just push something and assume that the site regenerated without actually watching the output.
The command to regenerate the site is npx @11ty/eleventy. I had assumed that putting an ampersand at the end of that would make it exit right away without waiting for the command to finish. However, it still waits for the command to finish, and git shows me the full output of that command before I can use the terminal again.
What can I do to just make that script exit right after it calls the npx command, and not actually wait for npx to finish?
The full script right now is:
#!/bin/bash
cd ../eleventy-site
npx @11ty/eleventy &
edit: Thanks to the recommendations from @cecilkorik@lemmy.ca and @sin_free_for_00_days@sopuli.xyz, I tried a few more things and found something that worked. I don’t understand why this works, but it does:
bash -c "npx @11ty/eleventy &" &> /dev/null
You do have to do bash -c instead of just calling the command, and both the & inside of the quotes and after it are necessary, and the > /dev/null is necessary, too.


Thanks, this is a great explanation. I’ll try doing
&> /dev/null &tomorrow. I’d like to find the simplest version of this for recommending to other people.