Is there way for a bash script to know if it is running in the foreground or background, and so it can behave slightly differently in each case?
Bash – How to a bash script detect if it is running in the background
bashshell
bashshell
Is there way for a bash script to know if it is running in the foreground or background, and so it can behave slightly differently in each case?
Best Answer
Quoting
man ps
:PROCESS STATE CODES
So you could perform a simple check: