Historically, in cleanly configured bourne-style shells, it's "test if PS1 is set", but that's broken if some joker exports PS1 to the environment.
The SUS standards-compliant method is to test if 'i' is in $-, as Dennis notes, although [[ ... ]] is non-standard, as is the == comparator. So the most portable standards-compliant check is:
case $- in
*i*) # do interactive stuff
;;
esac
Then you have shopt -q login_shell for bash (per Cakemox), and both [[ -o interactive ]] and [[ -o login ]] for zsh.
In bash, I use
shopt -q login_shell
to test for that. For example in .bashrc:This should keep the "interesting stuff" out of your scp/sftp.
According to the man page, you should test for the presence of "i" in
$-
.For example:
Historically, in cleanly configured bourne-style shells, it's "test if PS1 is set", but that's broken if some joker exports PS1 to the environment.
The SUS standards-compliant method is to test if 'i' is in $-, as Dennis notes, although [[ ... ]] is non-standard, as is the == comparator. So the most portable standards-compliant check is:
Then you have
shopt -q login_shell
for bash (per Cakemox), and both[[ -o interactive ]]
and[[ -o login ]]
for zsh.