#!/bin/bash while getopts ':V:L' flag; do case "${flag}" in V) VERSION="${OPTARG/./\.}\\b" ;; L) LIST="YES" ;; esac done if [[ $VERSION ]]; then candidates=$(ls $(dirname $BASH_SOURCE) | grep "^nomsu$VERSION[0-9.]*$") else candidates=$(ls $(dirname $BASH_SOURCE) | grep "^nomsu[0-9.]\+$") fi if [[ $LIST ]]; then echo "$candidates" exit fi if [[ $candidates ]]; then eval $(dirname $BASH_SOURCE)/$(echo "$candidates" | sort -V | tail -n 1) $@ else echo "Failed to find a Nomsu version matching the regex: \"nomsu$VERSION\"" echo "The versions available are:" ls $(dirname $BASH_SOURCE) | grep "^nomsu[0-9.]\+$" | sed 's/^/ * /' fi