Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Date: 2010feb21 Language: bash Q. How can a bash script accept options with a dash (-) ? A. Use the builtin getopts (not the external getopt) like this:#!/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
Add a commentSign in to add a comment