I want to create a script that runs when a Zsh instance starts, but only if the instance is:Non-login.InteractiveI think I'm right to say .zshrc runs for all interactive shell instances, .zprofile and .zlogin run for all login shells, and .zshenv runs in all cases.The reason I want to do this is to check if there is an existing ssh-agent running, and make use of it in the newly opened shell if there is.I imagine any tests carried out would be best placed in .zshrc (as this guarantees an interactive shell) and the designated non-login event script called from there.I probably first want to check if the new shell is already running as part of an existing remote SSH session before testing for the ssh-agent, but I have found this SE recipe for this purpose.I pick Zsh as it is the shell I favor, but I imagine any correct technique to do this would apply similarly to other shells.
How would I detect a non-login shell? (In Zsh)
shell script;zsh;configuration;ssh agent;interactive
if [[ -o login ]]; then  echo I'm a login shellfiif [[ -o interactive ]]; then  echo I'm interactivefi[[ -o the-option ]] returns true if the-option is set.You can also get the values of options with the $options special associative array, or by running set -o.To check if there's an ssh-agent:if [[ -w $SSH_AUTH_SOCK ]]; then  echo there's onefiIn ksh (and zsh):case $- in (*i*) echo interactive; esaccase $- in (*l*) echo login; esacIn bash, it's a mess, you need:case $- in *i*) echo interactive; esac # that should work in any Bourne/POSIX shellcase :$BASHOPTS: in (*:login_shell:*) echo login; esacAnd $SHELLOPTS contains some more options. Some options you can set with set -<x>, some with set -o option, some with shopt -s option.