Skip to content

Instantly share code, notes, and snippets.

@lwcorp
Created March 25, 2024 14:07
Show Gist options
  • Save lwcorp/179551930440bfead0c29fdef452b518 to your computer and use it in GitHub Desktop.
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)
#!/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