bash
To see the version:
$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
To get the version:
$ bash --version | awk '{print $4}' | head -1
3.2.57(1)-release
To get the major version:
$ bash --version | awk '{print $4}' | head -1 | awk -F. '{print $1}'
3
Check out this post to learn how to parse semver with
awk
.
node
To see the version:
$ node --version
v12.16.2
$ node -v
v12.16.2
To cut the v
out from the version:
$ node -v | cut -c 2-
12.16.2
To get the major version:
$ node -v | cut -c 2- | awk -F. '{print $1}'
12
Check out this post to learn how to parse semver with
awk
.
python
To see the version:
$ python --version
Python 2.7.17
$ python -V
Python 2.7.17
To remove Python
from the version:
$ python -V 2>&1 | awk '{print $2}'
2.7.17
We’re redirecting stderr to stdout with 2>&1
because python writes the version to stderr.
To get the major version:
$ python -V 2>&1 | awk '{print $2}' | awk -F. '{print $1}'
2
Check out this post to learn how to parse semver with
awk
.
php
To see the version:
$ php --version
PHP 7.1.33 (cli) (built: Jan 26 2020 22:52:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
$ php -v
PHP 7.1.33 (cli) (built: Jan 26 2020 22:52:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
To get the version and remove all extraneous details:
$ php -v | awk '{print $2}' | head -1
7.1.33
To get the major version:
$ php -v | awk '{print $2}' | head -1 | awk -F. '{print $1}'
7
Check out this post to learn how to parse semver with
awk
.
ruby
To see the version:
$ ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
To get the version:
$ ruby -v | awk '{print $2}'
2.7.0p0
To get the major version:
$ ruby -v | awk '{print $2}' | awk -F. '{print $1}'
2
Check out this post to learn how to parse semver with
awk
.