Skip to content

Instantly share code, notes, and snippets.

@namikingsoft
Created June 19, 2026 08:22
Show Gist options
  • Select an option

  • Save namikingsoft/af0c445d5651d9a739ec25b691fbebf1 to your computer and use it in GitHub Desktop.

Select an option

Save namikingsoft/af0c445d5651d9a739ec25b691fbebf1 to your computer and use it in GitHub Desktop.
Bash Arguments Example
#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: bash compare.sh --head <branch> --base <base_branch> [--dir <dirpath>]"
exit 1
}
BRANCH_NAME=""
BASE_BRANCH=""
DIR="test"
while [[ $# -gt 0 ]]; do
case "$1" in
--head) BRANCH_NAME="$2"; shift 2 ;;
--base) BASE_BRANCH="$2"; shift 2 ;;
--dir) DIR="$2"; shift 2 ;;
*) usage ;;
esac
done
if [ -z "$BRANCH_NAME" ] || [ -z "$BASE_BRANCH" ]; then usage; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment