Skip to main content
added 612 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi

[[ -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 one"
fi

In ksh (and zsh):

case $- in (*i*) echo interactive; esac
case $- in (*l*) echo login; esac

In bash, it's a mess, you need:

case $- in *i*) echo interactive; esac # that should work in any Bourne/POSIX shell
case :$BASHOPTS: in (*:login_shell:*) echo login; esac

And $SHELLOPTS contains some more options. Some options you can set with set -<x>, some with set -o option, some with shopt -s option.

if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi

To check if there's an ssh-agent:

if [[ -w $SSH_AUTH_SOCK ]]; then
  echo "there's one"
fi
if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi

[[ -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 one"
fi

In ksh (and zsh):

case $- in (*i*) echo interactive; esac
case $- in (*l*) echo login; esac

In bash, it's a mess, you need:

case $- in *i*) echo interactive; esac # that should work in any Bourne/POSIX shell
case :$BASHOPTS: in (*:login_shell:*) echo login; esac

And $SHELLOPTS contains some more options. Some options you can set with set -<x>, some with set -o option, some with shopt -s option.

added 109 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi

To check if there's an ssh-agent:

if [[ -w $SSH_AUTH_SOCK ]]; then
  echo "there's one"
fi
if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi
if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi

To check if there's an ssh-agent:

if [[ -w $SSH_AUTH_SOCK ]]; then
  echo "there's one"
fi
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

if [[ -o login ]]; then
  echo "I'm a login shell"
fi

if [[ -o interactive ]]; then
  echo "I'm interactive"
fi