Skip to main content
updated
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then           # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH""$BASH_VERSION" ] && shopttype -qcaller >/dev/null 2>&1; then                # bash
  MYSHELL=`command -v bash`
elif [ -x "$shell" ] && which setenv |grep -l builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then        # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then                # bash
  MYSHELL=`command -v bash`
elif [ -x "$shell" ] && which setenv |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then           # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH_VERSION" ] && type caller >/dev/null 2>&1; then        # bash
  MYSHELL=`command -v bash`
elif [ -x "$shell" ] && which setenv |grep -l builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

tcsh tweak
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then        # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then                # bash
  MYSHELL=`command -v bash`
elif [ -x "$shell" ] && which setenv ls-F |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then      # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then              # bash
  MYSHELL=`command -v bash`
elif which setenv ls-F |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then        # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then                # bash
  MYSHELL=`command -v bash`
elif [ -x "$shell" ] && which setenv |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

csh can't do `>&2`
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then      # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then              # bash
  MYSHELL=`command -v bash`
elif which setenv ls-F 2>/dev/null |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!" >&2
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells will complain about thecan't do 2>/dev/null since they have no equivalentor >&2, as noted in the famous Csh Programming Considered Harmful rant.)

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then      # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then              # bash
  MYSHELL=`command -v bash`
elif which setenv ls-F 2>/dev/null |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!" >&2
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells will complain about the 2>/dev/null since they have no equivalent, as noted in the famous Csh Programming Considered Harmful rant.)

I set $MYSHELL for future tests in my shell-agnostic ~/.aliases:

unset MYSHELL
if [ -n "$ZSH_VERSION" ] && type zstyle >/dev/null 2>&1; then      # zsh
  MYSHELL=`command -v zsh`
elif [ -x "$BASH" ] && shopt -q >/dev/null 2>&1; then              # bash
  MYSHELL=`command -v bash`
elif which setenv ls-F |grep builtin >/dev/null; then  # tcsh
  echo "DANGER: this script is likely not compatible with C shells!"
  sleep 5
  setenv MYSHELL "$shell"
fi

# verify
if [ ! -x "$MYSHELL" ]; then
  MYSHELL=`command -v "$(ps $$ |awk 'NR == 2 { print $NF }')"`
  [ -x "$MYSHELL" ] || MYSHELL="${SHELL:-/bin/sh}"  # default if verify fails
fi

The tcsh section is likely unwise to roll into a POSIX-style script since it's so radically different (thus the warning and five second pause). (For one, csh-style shells can't do 2>/dev/null or >&2, as noted in the famous Csh Programming Considered Harmful rant.)

actually tested the csh part, also included my "verify" section
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35
Loading
actually tested the csh part
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35
Loading
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35
Loading