I know of two ways to test whether a shell is interactive,
[[ $- == *i* ]] && echo "-i option flag indicates interactive" [ -n "$PS1" ] && echo "prompt is set"
I've read that checking for the
i option flag is more reliable, which makes sense given that it's an explicit indicator of interactivity.
But when I look through the startup files on my system (e.g.
/etc/bash.bashrc), they check
PS1. I'm running Ubuntu. I don't know how platform-specific this is.
I'm wondering whether this means:
- the authors of the startup files are not as skilled as I assumed
PS1is reliable enough in this context
PS1is reliable enough in general, and I'm overthinking things