# shtype - determine shell type (hs '96, 1.5) # Heiner Steven (heiner@hsysnbg.nbg.sub.org), Public Domain. # # Note: this script *must* start with a '#' character, because otherwise # "csh" may use "sh" to run it. # # Knows sh, ksh, ksh93, csh, tcsh, bash, zsh # # Thanks to # Dave Plonka (BSH) # # Check for Bourne shell or C shell dialect set x = 1 test "$x" = 1 && goto CSH # Bourne shell dialect # Don't use external commands PATH=; export PATH # ASH (FreeBSD/NetBSD sh) has a non-standard "setvar" command # This test has to be the first, because otherwise ASH would # terminate this script with the next test. x=`(a=; setvar a b; echo $a) 2>/dev/null` if [ X"$x" = Xb ] then echo ASH exit 0 fi # The standard Bourne shell does not know how to remove parts # of a variable with ${VAR%%pattern}. x="A.B" x=`(echo ${x%%.*}) 2>/dev/null` if [ "$x" = A ] then # bash/zsh or ksh? # bash/zsh use $[...] for arithmetic evaluation. x=`(echo $[0+1]) 2>/dev/null` if [ "$x" = 1 ] then # zsh tests with ${+x} if variable x is set x=0 x=`(echo ${+x}) 2>/dev/null` if [ "$x" = 1 ] then echo "ZSH $ZSH_VERSION" else echo "BASH $BASH_VERSION" fi else # ksh or ksh93? # ksh93 can extract substrings from a variable. x=AB x=`(echo ${x:1:1}) 2>/dev/null` if [ "$x" = B ] then echo "KSH93 ${.sh.version}" else # ksh or POSIX shell? POSIX shell treats prefix 0 as octal res="$((010+10))" if [ ${res:=0} -eq 18 ] then echo KSH "(POSIX)" ${KSH_VERSION-$KSH_VERSION} elif [ $res -eq 20 ] then echo KSH ${KSH_VERSION-$KSH_VERSION} else exit 1 # unknown ksh-similar shell fi fi fi else echo BSH fi exit 0 CSH: # C-Shell dialect # tcsh has a bindkey command if { bindkey >& /dev/null } then echo "TCSH $version" else echo CSH endif exit 0