0

I have to write script in unix.

When I call it like:

./check -l word1 -c word2,

I need to fetch the word which is used with commands -l and -c from inside script.

pankaj_ar
  • 757
  • 2
  • 10
  • 33

1 Answers1

0

Use getopts as shown in the following script:

#!/bin/bash

while getopts l:c: option
do
    case "$option" in
        l) 
           loption="$OPTARG"
           ;;
        c)
           coption="$OPTARG"
           ;;
    esac
done

echo "L is: $loption"
echo "C is: $coption"
dogbane
  • 266,786
  • 75
  • 396
  • 414