On 2015-02-17 08:06 PM, John Merriam wrote:
I definitely agree that the silliness of checking a version string to
possibly use some exotic or non-standard feature of a particular
flavor of a particular family of shells is not a good idea when
writing a shell script. If you can't do what you want without relying
on that particular feature then maybe what you're writing shouldn't be
a shell script. If it's a bug in a particular flavor of a shell, then
instead of checking for and working around it, report the bug to the
author/maintainer.
Jumping in late in the conversation...
This is not an academic point; as an ISV, I've had to do this sort of
thing in the past, and will have to do so again in the future.
There is no "standard" or universal way to detect what version of what
shell happened to get invoked on what operating system, so an ISV must
rely on tricks and silliness like checking the version string to make
what amounts to an educated guess.
For example, I have a customer that must run a specific (non-current)
version of HP-UX due to hard dependencies in a mission-critical
line-of-business app. Yes, that means there's a foundational problem,
but it would cost ~$100M to fix now. Not going to happen.
"Report the bug to the author/maintainer" is all very well, but HP isn't
going to issue a patch for an old version of HP-UX just because one
customer complains about /bin/ksh behaving badly. (Actually, they very
well might, given sufficient financial incentive, but that's another
story altogether...)
Meanwhile, portable shell scripts must continue to run - portably -
across multiple OSes.
Array handling is the big bugbear I run into; if I can handle arrays
inside the shell, I don't have to resort to using tmpfiles and
fork/exec'ing multiple external utilities to simulate the
functionality. Which means, firstly, determining if I'm inside
something ksh-like or bash-like, or if I'm running in a simple POSIX
shell. There are virtually no safe assumptions that can be made in
portable shell scripting - how was the script invoked? Sourced?
Hash-bang? Explicit "/bin/sh script" invocation?
It's a mess, despite POSIX' attempt to unify things; the choice is to
either code for lowest-common-denominator, which typically results in
payloads up to 10x larger and that run up to 10x slower, or to probe for
advanced features and exit cleanly and safely if they're absent.
--
-Adam Thompson
athom...@athompso.net
+1 (204) 291-7950 - cell
+1 (204) 489-6515 - fax