Get Nginx Version With grep
It’s really easy to get the version of Nginx installed through your package manager or just from visual inspection, but there’s a small hurdle to overcome if you need to programmatically check the version when a package manager isn’t available.
For some reason, nginx -v
spits out the version number to stderr, so a simple pipe will always return an exit status of 1
even if there is a match:
nginx -v | grep <version number here>
To fix this, redirect Nginx’s output from stderr to stdout and then pipe to grep:
nginx -v 2>&1 | grep <version number here>
That way, a match in grep with return an exit status of 0
.
comments powered by Disqus