#!/bin/bash VERBOSE=no while getopts "v" flag; do ## echo "$flag" $OPTIND $OPTARG if [[ $flag == v ]]; then VERBOSE=yes fi done ... later on ... if [[ $VERBOSE == yes ]]; then echo blah fi
Programming Tips - bash: How can a bash script accept options with a dash (-) ?
Date: 2010feb21
Language: bash
Q. bash: How can a bash script accept options with a dash (-) ?
A. Use the builtin getopts (not the external getopt) like this: