How to Run Hugo Serve in a Script Without Blocking Terminal?

0
9
Asked By CuriousCat42 On

I'm trying to create a script for my Hugo website that will help streamline posting. The issue I'm facing is that when I run `hugo serve` in the script, it takes over the terminal, preventing me from returning to the script. When I hit Ctrl-C to stop `hugo serve`, it also exits my whole script. I want to know if there's a way to run `hugo serve`, check my site in Firefox, and then continue with the script without it getting interrupted. Here's a snippet of my script:

`echo "Move to next step [Y] or exit [q]?"`

`read -r editing_finished`

`if [ $editing_finished = q ]; then`

`exit`

`elif [ $editing_finished = Y ]; then`

`# Step 6 Run hugo serve`

`cd ../../../`

`# Run hugo local server and display in firefox`

`hugo serve & firefox http://localhost:1313/`

`fi`

Any help would be appreciated!

3 Answers

Answered By DevGuru88 On

You might want to open a new terminal window for Hugo. It can keep your current terminal free for script execution.

Answered By CodeWizard99 On

If you run `hugo serve & firefox ...` it should only let Hugo output texts while Firefox takes over the input. You can silence Hugo's output with `&> /dev/null`. To stop the server later, you could track its process ID by doing `hugo serve & hugopid="$!"` and then kill that process when you're done.

Answered By TechieTom On

Instead of changing directories in your script, consider using the full path to your Hugo installation. For example: `/path/to/hugo serve`. This can help avoid issues related to directory changes.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.