Update :
A solution that identifies and downloads the latest stable version through http://nginx.org/en/download.html ( http://nginx.org/download/ used in the original solution below does not distinguish between stable and major versions) - works with both Linux and OSX:
Note. It depends on the structure of the HTML page http://nginx.org/en/download.html , which is not the most reliable solution.
The original solution , which defines the latest version through http://nginx.org/download/ , where no distinction is made between stable and major versions:
On Linux, try:
# Determine latest version: latestVer=$(curl 'http://nginx.org/download/' | grep -oP 'href="nginx-\K[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -rn -k1,1 -k2,2 -k3,3 | head -1)
It does not depend on the specific listing order http://nginx.org/download/ ; instead, version numbers are retrieved and sorted accordingly.
On OSX - where grep does not support -P and \K not available to remove the left side of the match, try:
# Determine latest version: latestVer=$(curl 'http://nginx.org/download/' | egrep -o 'href="nginx-[0-9]+\.[0-9]+\.[0-9]+' | sed 's/^href="nginx-//' | sort -t. -rn -k1,1 -k2,2 -k3,3 | head -1)
mklement0
source share