Rose
Rose

Reputation: 423

While loop providing inputs in shell script

while getopts "f:t:d:g:o:p:b:q:r:" opt; do
    case "$opt" in

(f)fan=${OPTARG}
(t)..
 esac
done
shift $(( OPTIND - 1 ));

How to provide input? Can anyone plz tell me how to provide input for the above mentioned code snippet?

Upvotes: 1

Views: 65

Answers (1)

Rose
Rose

Reputation: 423

I got the answer: We can provide the input like -f inputvalue

#!/bin/bash

while getopts "f:t:d:g:o:p:b:q:r:" opt; do
  case "$opt" in

  f) fan=${OPTARG}
  ;;
  t) echo "doing somthing with option t = $OPTARG"
  ;;
 esac
done
shift $(( OPTIND - 1 ));

and run as

$ ./script.sh -f admin
doing somthing with option f = admin

Upvotes: 2

Related Questions