Обработка аргументов в bash

#!/bin/bash

while [[ "$#" -gt 0 ]]; do
    case $1 in
        -t|--target) target="$2"; shift ;;
        -u|--uglify) uglify=1 ;;
        *) echo "Unknown parameter passed: $1"; exit 1 ;;
    esac
    shift
done

echo "Where to deploy: $target"
echo "Should uglify  : $uglify"
Usage:

./deploy.sh -t dev -u

# OR:

./deploy.sh --target dev --uglify
Print Friendly, PDF & Email

Добавить комментарий