Memos - Bash helper

Optionnal input argument

VAR=${1-”default”}

Exit

exit 0 # ok
exit 1 # error

Test dir

if test -d ${DIR}; then
  echo "Directory already exists."
  exit 1
fi

Test with regexp

test_version () {
  if [[ $1 =~ ^6\.(9|1[0-9]+)\. ]]; then
    echo "${1} match 6.9+ regex";
  else
    echo "${1} DONT match 6.9+ regex";
  fi

  if [[ $1 =~ ^6\.[0-8]\. ]]; then
    echo "${1} match 6.8- regex";
  else
    echo "${1} DONT match 6.8- regex";
  fi
}

test_version "6.9.0"
test_version "6.8.1"