-
-
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
- All browsers pretend they're Mozilla
- LLVM Has to Pretend It's GCC
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 justification for eval
!
For example, you can test if a shell has declare
with something like eval 'declare myvar'; echo $?
.