-
-
Notifications
You must be signed in to change notification settings - Fork 166
Feature Detection Is Better than Version Detection
andychu edited this page Jun 25, 2019
·
12 revisions
Summary: Version Detection like checking $BASH_VERSION
or User-Agent == "Mozilla"
is bad for portability.
TODO: Fill out this page more.
-
Comment on Hacker News Thread: Bash Completion in JSON Fields
- An unnecessary
$BASH_VERSION
check --eval 'complete ...'
would suffice.
- An unnecessary
- All browsers pretend they're Mozilla because web servers detect it
- LLVM Has to Pretend It's GCC to compile code in the wild
NOTE: OSH won't pretend it's bash! It is largely compatible with bash, but not identical.
In shell (or JavaScript), an easy and effective way is to use eval
. (This is perhaps the best reason to use eval
!)
For example, you can test if a shell has declare
with something like eval 'declare myvar'; echo $?
.