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?
PROCESS STATE CODES
So you could perform a simple check:
Look at the file /etc/bash.bashrc".
The line that has "$PS1". Then do a "man bash" and look for the token PS1.
exits a script that is not interactive.
Hope this helps.