Terrence J. Doyle a écrit :
Cyrille Lefevre wrote:
how about :
if [ "${RANDOM}" != "${RANDOM}" ]; then
is='ksh'
else
is='sh'
fi
that was the short answer...
The $(id) and ${RANDOM} tests both give a false positive if ksh, bash or
zsh is masquerading as sh. Nowadays, it's common to find that /bin/sh is
actually bash and that there's no true Bourne Shell on the system. If
you want to know the basename of the shell executable you're running,
the classic $0 test does the job. For /etc/profile that should be good
enough. But, if you really want to know which shell you're currently
running, this version test is probably what you're looking for:
if ( [ -n "${.sh.version}" ] ) 2>&- # ${.sh.version} causes an error
message in non-ksh shells.
then
is=ksh
elif [ -n "$BASH_VERSION" ]
then
is=bash
elif [ -n "$ZSH_VERSION" ]
then
is=zsh
else
is=sh
fi
your test may cause script to exit if set -u is true due to 1st line,
how about this, the long answer, which I use for years :
if [[ -n ${BASH_VERSION:-} ]]; then
is='bash'
elif [[ -n ${KSH_VERSION:-} ]]; then
is='pdksh'
elif [[ -n ${ZSH_VERSION:-} ]]; then
is='zsh'
elif [[ ${RANDOM:-} != ${RANDOM:-} ]]; then
if [[ ${SECONDS:-} = *'.'* ]]; then
is='ksh93'
else
is='ksh88'
fi
else
is='posixsh'
fi
note that $SECONDS is a float under ksh93 and an integer under ksh88 :)
non posix sh don't have $RANDOM as I far as I know.
Regards,
Cyrille Lefevre
--
mailto:[EMAIL PROTECTED]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users