15
submitted 1 day ago* (last edited 1 day ago) by tuckerm@feddit.online to c/programming@programming.dev

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.

you are viewing a single comment's thread
view the rest of the comments
[-] Vulwsztyn@programming.dev 1 points 1 day ago
this post was submitted on 07 Dec 2025
15 points (100.0% liked)

Programming

23761 readers
78 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS