How to get the binary version


Get the version of:

bash

See the version:

bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.

Get the version:

bash --version | awk '{print $4}' | head -1
3.2.57(1)-release

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

See the version:

node --version # node -v
v12.16.2

Cut the v out from the version:

node -v | cut -c 2-
12.16.2

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

See the version:

python --version # python -V
Python 2.7.17

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.

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

See the version:

php --version # 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

Get the version and remove all extraneous details:

php -v | awk '{print $2}' | head -1
7.1.33

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

See the version:

ruby --version # ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]

Get the version:

ruby -v | awk '{print $2}'
2.7.0p0

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.



Please support this site and join our Discord!