-2

If I have a script called program and I want to set an option so that if -p is entered as an option then the program echoes "polly want a cracker", how should I go use getopt for this?

cdarke
  • 40,173
  • 7
  • 78
  • 79
jyu429
  • 71
  • 2
  • 5
  • `getopt` is a C library routine, you need `getopts` , which is a shell builtin. See `help getopts`. – cdarke Jun 20 '15 at 08:14

1 Answers1

1

I give you a little example which you can develop for your own needs :

#!/bin/bash

while getopts "bp" OPTION
do
    case $OPTION in
        b)
            echo "polly want a banana"
            ;;
        p)
            echo "polly want a cracker"
            ;;
    esac
done
alifirat
  • 2,789
  • 1
  • 15
  • 33