From f63dd699bc97b1378c757dabb48b6baaccf1a621 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 17 Dec 2016 20:38:27 +1300 Subject: Still improving ksh-guessing heuristics --- ksh/shrc.d/ksh.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'ksh/shrc.d/ksh.sh') diff --git a/ksh/shrc.d/ksh.sh b/ksh/shrc.d/ksh.sh index 6c134e88..0045a470 100644 --- a/ksh/shrc.d/ksh.sh +++ b/ksh/shrc.d/ksh.sh @@ -5,18 +5,25 @@ # Unfortunately, this isn't very simple, because KSH_VERSION is set by PDKSH # and derivatives, and in ksh93t+ and above, but not in earlier versions of -# ksh93. +# ksh93. To make matters worse, the best way I can find for testing the version +# makes other shells throw tantrums. -# If it's not already set, we'll try hard to set it to something before we -# proceed ... +# Does the name of our shell have "ksh" in it at all? This is in no way +# guaranteed. It's just a heuristic that e.g. Bash and Yash shouldn't pass. +case $0 in + *ksh*) ;; + *) return ;; +esac + +# If KSH_VERSION is not already set, we'll try hard to set it to something +# before we proceed ... if [ -z "$KSH_VERSION" ] ; then - # Test whether we have content in the .sh.version variable. The odd name - # causes at least Bash to panic, so we suppress errors, and we run it in a - # subshell to work around parsing error precedence. + # Test whether we have content in the .sh.version variable. Suppress errors + # and run it in a subshell to work around parsing error precedence. ( test -n "${.sh.version}" ) 2>/dev/null || return - # If it is, that's our KSH_VERSION + # If that peculiarly named variable was set, then that's our KSH_VERSION KSH_VERSION=${.sh.version} fi -- cgit v1.2.3