How to run background command with nohup

Problem

Imagine you’re creating a script that runs redis-server then redis-cli:

redis-server
redis-cli

Solution

One solution is to run redis-server in the background with &:

redis-server &
nohup redis-server &
cat nohup.out
nohup redis-server redis.conf &
nohup redis-server redis.conf >/dev/null 2>&1 &
nohup redis-server &
redis-cli
nohup redis-server &
echo $! > /tmp/redis-server.pid
kill $(cat /tmp/redis-server.pid)

Script

Working example script:

Demo

Replit:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store