Advertisement
sheffield

getopts-arg.sh

Mar 14th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. while getopts ":a:" opt; do
  4.   case $opt in
  5.     a)
  6.       echo "-a was triggered, Parameter: $OPTARG" >&2
  7.       ;;
  8.     \?)
  9.       echo "Invalid option: -$OPTARG" >&2
  10.       exit 1
  11.       ;;
  12.     :)
  13.       echo "Option -$OPTARG requires an argument." >&2
  14.       exit 1
  15.       ;;
  16.   esac
  17. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement