How can I safely get the version of ksh from within a ksh script?
I have seen the following solutions:
ksh --version
echo ${.sh.version}
echo $KSH_VERSION
And given the right circumstances, each of these works correctly. However, I care about the non-perfect case.
Specifically, there are several machines I work with that have older versions of ksh that, for my purposes, are severely lacking in functionality. Anyway, the reason I want to check the version (programmatically) is to see if the ksh version is one of the less capable versions; and if so, I want to execute a branch with less awesome code.
However, on the problematic machines, the shell's ineptitude extends into checking the version...
- If I try
ksh --version
, it prints nothing and opens a new instance ofksh
! If I try
echo ${.sh.version}
,ksh
treats this as a syntax error that cannot be discarded with2> /dev/null
.$ echo ${.sh.version} 2> /dev/null ksh: ${.sh.version}: bad substitution
Of course
echo $KSH_VERSION
appears to work fine – I mean it won't crash – though on these machines it's blank. Also, I saw somewhere thatKSH_VERSION
is set only bypdksh
.
Questions:
- How can I safely check the version of
ksh
programmatically? For my purposes here, I don't really care what the actual version number is, just whether it's an outdated version ofksh
. - Is
$KSH_VERSION
good enough? I mean if it's blank, then isksh
necessarily an outdated version? Was that other forum correct that it might not be set even for newer versions ofksh
? - Is there just no way to check this at all?
PS1
to use this function. However, Old ksh does not support$()
inPS1
. So if it's a modern version of ksh, I wantPS1
to use the function I created; if it's the old version, I use just$PWD
. – Sildoreth May 04 '15 at 12:44