Skip to content

Instantly share code, notes, and snippets.

@tihasdop
Last active February 6, 2023 16:18
Show Gist options
  • Save tihasdop/c9817257980675133a5d597215b35e3d to your computer and use it in GitHub Desktop.
Save tihasdop/c9817257980675133a5d597215b35e3d to your computer and use it in GitHub Desktop.
nohup wrapper to run a command separate from the TTY and without any output
#!/bin/sh
if [ -z "$1" ] || [ "$1" = '--help' ]; then
echo 'nohup wrapper to run a program separate from the TTY' \
'and without any output'
echo
echo "Read 'man nohup' for further info"
exit 1
elif echo "$1" | grep -q '/'; then
if [ ! -f "$1" ]; then
echo "ERROR: '$1' is not found"
exit 2
elif [ ! -x "$1" ]; then
echo "ERROR: '$1' is not executable"
exit 3
fi
elif ! which "$1" >/dev/null 2>&1; then
echo "ERROR: '$1' is not found in PATH"
exit 4
fi
nohup $* >/dev/null 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment