1
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?

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.