Sunday 17 January 2016

Bash shell script getops example

#! /bin/bash

#process the command line argument using getopts
#take action based on input

while getopts :h:r:l: OPTION
do
        case $OPTION in
        h)
                echo "help of $OPTARG"
                help "$OPTARG"
        ;;
        r)
                echo "Going to remove a file $OPTARG"
                rm -f "$OPTARG"
        ;;
        *)
                echo "Unknown option"
                echo "Usage: sh getopt.sh [-hrl] [value]"
        ;;
        esac
done

No comments:

Post a Comment