Created
March 25, 2024 14:07
-
-
Save lwcorp/179551930440bfead0c29fdef452b518 to your computer and use it in GitHub Desktop.
Run a Go script portably and with parameters optionally in the background (allowing to keep working normally in Terminal)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
background=true | |
MAIN_PATH=/home/youruser/public_html/yourfolder | |
MAIN_FILE=your Go script WITHOUT extension | |
export TMPDIR=$MAIN_PATH/tmp/ | |
cd $MAIN_PATH | |
if ! $background; then | |
go run $MAIN_FILE.go "$@" | |
else | |
go build $MAIN_FILE.go | |
nohup ./$MAIN_FILE "$@" >/dev/null 2>nohup.out & | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment