From 0516998fccb9c034b0b39081fa196ed32737eb08 Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Fri, 25 Jun 2021 09:44:11 -0700 Subject: [PATCH] Use $- to determine if interactive Instead of checking for environment variable $PS1 (which could be blindly set by a user or script somewhere), ask Bash if it is interactive by interrogating $- automatic variable. If it contains 'i' then the shell was started interactively. --- bashrc_dispatch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bashrc_dispatch b/bashrc_dispatch index bd3e15e..948a26a 100644 --- a/bashrc_dispatch +++ b/bashrc_dispatch @@ -41,7 +41,7 @@ if ! type -p shell_is_login ; then shell_is_osx () { [[ "$OSTYPE" == *'darwin'* ]] ; } shell_is_cygwin () { [[ "$OSTYPE" == *'cygwin'* ]] ; } shell_is_login () { shopt -q login_shell ; } - shell_is_interactive () { test -n "$PS1" ; } + shell_is_interactive () { [[ "$-" == *'i'* ]] ; } shell_is_script () { ! shell_is_interactive ; } fi