From 1739c457836732e51e18411bb6cbdac1672def7a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 17 Dec 2016 19:42:10 +1300 Subject: Improve ksh version test to catch ksh93s+ And hopefully all versions below --- sh/shrc.d/ksh.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'sh/shrc.d/ksh.sh') diff --git a/sh/shrc.d/ksh.sh b/sh/shrc.d/ksh.sh index 5e9fee3b..befa60ee 100644 --- a/sh/shrc.d/ksh.sh +++ b/sh/shrc.d/ksh.sh @@ -2,7 +2,31 @@ # configuration if it was defined or if we can find it. Bash and Zsh invoke # their own rc files first, which I've written to then look for ~/.shrc; ksh # does it the other way around. -[ -n "$KSH_VERSION" ] || [ -n "${.sh.version}" ] || return + +# 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. + +# If it's not already set, we'll try hard to set it to something before we +# proceed ... +if [ -z "$KSH_VERSION" ] ; then + + # Do we have the '[[' builtin? Good start + command -v '[[' >/dev/null 2>&1 || return + + # Use the '[[' builtin to test whether $.sh.version is set (yes, that's a + # real variable name) + [[ -v .sh.version ]] || return + + # If it is, that's our KSH_VERSION + KSH_VERSION=${.sh.version} +fi + +# If KSH_ENV isn't already set, set it [ -n "$KSH_ENV" ] || KSH_ENV=$HOME/.kshrc + +# Check the file named in KSH_ENV exists [ -f "$KSH_ENV" ] || return + +# Source it (finally) . "$KSH_ENV" -- cgit v1.2.3