verbose=0
output="out.txt"
dry_run=0
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--verbose) verbose=1; shift ;;
-o|--output) output="$2"; shift 2 ;;
--output=*) output="${1#*=}"; shift ;;
-n|--dry-run) dry_run=1; shift ;;
-h|--help) echo "usage: ..."; exit 0 ;;
--) shift; break ;; # stop flag parsing
-*) echo "Unknown flag: $1" >&2; exit 2 ;;
*) args+=("$1"); shift ;;
esac
done
echo "verbose=$verbose output=$output dry_run=$dry_run positional=${args[*]:-}"
# Call as:
# ./script.sh -v --output=foo.txt input1 input2
# ./script.sh --dry-run -o foo.txt input1
Create a free account and build your private vault. Share publicly whenever you want.