Created
August 22, 2017 09:00
-
-
Save themerius/93c3487b4cd9ba7fbe46a273eb847c57 to your computer and use it in GitHub Desktop.
Get newest version with Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Portable script (Linux, Mac/BSD) to detect the folder with the newest version. | |
| # Assume: | |
| # We have a folder structure like this: | |
| # | |
| # /path/to/my_program/my-program-0.1.0/ | |
| # /path/to/my_program/my-program-0.5.0/ | |
| # /path/to/my_program/my-program-0.10.0/ | |
| # /path/to/my_program/my-program-1.0.0/ | |
| # ... | |
| # | |
| # Objective: | |
| # We want to detect the folder with the newest version of our program. | |
| # For example to start the newest version. | |
| APP_HOME_BASE="/path/to/my_program" | |
| # List only directories, sort them in numeric order, retrieve the first line, remove the trailing slash | |
| LATEST_APP_HOME=`cd $APP_HOME_BASE && ls -d */ | sort --reverse --numeric-sort | head -n 1 | cut -d'/' -f1` | |
| $LATEST_APP_HOME/bin/start-my_program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment