Subject: Re: CVS commit: basesrc/bin/ksh
To: None <firstname.lastname@example.org>
From: Joerg Klemenz <email@example.com>
Date: 10/04/2002 16:43:05
Simon J. Gerraty wrote:
> >if (echo $0|grep -q ksh)
> > ... ksh stuff
> Eek! What's wrong with:
> case /$0 in
> */ksh|*/-ksh) # we're ksh - yay!
> avoids any fork/exec
Here speaks thy old hacker... :-)
Unless performance is critical, I would rather take the "pretty"
version, but you are right, of course.
Here is what I just did:
$ time echo $0|grep -q ksh
0.03s real 0.00s user 0.00s system
$ time case $0 in *ksh) echo ksh ;; esac
0.01s real 0.01s user 42949672.95s system
(System: 100MHz Intel Pentium)
> >Still can't tell the difference between pdksh and ksh.
> That's the whole point. Well actually you can. The
> following is from my /etc/ksh.kshrc (bash users can set
> KSH_VERSION=BASH in .bashrc):
Thanks. I just inserted your code into my new /usr/local/sh-select
file. Now I do the following in profile, shrc or any other shell
case $SH_SELECT in
# ksh stuff
where sh-select sets the SH_SELECT variable obviously. That way any
user can benefit from the most sophisticated shell detection, and it
avoids code duplication (one of the seven deadly sins).
Actually I'm quite happy with this...