Cyrille Lefevre wrote:
>
> Andrew Clarke a écrit :
>> On Wed, 27 Aug 2008 12:18, Norman Ramsey wrote:
>>> In my new job, there's code in /etc/profile that contains a bash-ism:
>>> it's a test to see if the shell is a login shell. From a quick google
>>> search and perusal of the ksh man page, I can't see any obvious way
>>> to see from within the shell if it is a login shell, let alone anything
>>> that is portable across ksh and bash. (If you ask me a non-login
>>> shell
>>> has no business reading /etc/profile anyway, but people do the durndest
>>> things...)
>>>
>>
>> I use this slab right near the top of my /etc/profile; it's a steal
>> of the bash stuff that I found when I started using SuSE
>>
>> # Check which shell is reading this file
>> case "$0" in
>> *rbash*) is=bash ;;
>> *bash*) is=bash ;;
>> *rksh*) is=ksh ;;
>> *ksh*) is=ksh ;;
>> *ash*) is=ash ;;
>> *zsh*) is=zsh ;;
>> *) is=sh ;;
>> esac
>>
>> and copes with most known shells, even the useless ones.
>>
>> Way back, when I had to distinguish ksh from sh, I used to have
>>
>>
>> if [ "$(id)" != '$(id)' ]
>> then is=ksh
>> else is=sh
>> fi
>>
>> because the "$(id)" is magical on ksh but not on plain sh
>
> Cordialement,
>
> how about :
>
> if [ "${RANDOM}" != "${RANDOM}" ]; then
> is='ksh'
> else
> is='sh'
> fi
>
> Cyrille Lefevre
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
Terrence Doyle
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users