posted by Solver Full-stack Developer 2013.11.19 14:34

Step 1. add option word:


Step 2. add option case



#!/bin/bash

echo "OPTIND starts at $OPTIND"

while getopts ":p:q:d:" optname

  do

    case "$optname" in

      "p")

        echo "Option $optname is specified"

        ;;

      "q")

        echo "Option $optname has value $OPTARG"

        ;;

      "d")

        echo "Directory is $OPTARG"

        ;;

      "?")

        echo "Unknown option $OPTARG"

        ;;

      ":")

        echo "No argument value for option $OPTARG"

        ;;

      *)

      # Should not occur

        echo "Unknown error while processing options"

        ;;

    esac

    echo "OPTIND is now $OPTIND"

  done


reference : http://www.ibm.com/developerworks/opensource/library/l-bash-parameters/index.html


신고

티스토리 툴바