0

I am Having trouble using getopts where i am trying to parsing options but getting error:

Error: File not found with name : -a

Code:

while getopts ":a :b :c :d :e :f :g" opt; do

case $opt in

        a) FILETOPARSE=$OPTARG
           echo $compactAlarms
            ;;
        b) FILETOPARSE=${OPTARG}
           echo $nodeAlarms
            ;;
        c) FILETOPARSE=${OPTARG}
           echo $severityAlarms
            ;;
        d) FILETOPARSE=${OPTARG}
           echo $csvGentrator
            ;;
        e) FILETOPARSE=${OPTARG}
           echo $tableData
            ;;
        f) FILETOPARSE=${OPTARG}
           echo $help
            ;;
        g) FILETOPARSE=${OPTARG}
           echo $exit_function
            ;;
        *)
            echo "Error wrong Syntax,Opening help" && help
            ;;
    esac
done

Once it parses the data it'll call the function and display the data.

ewcz
  • 12,819
  • 1
  • 25
  • 47
Asnau Nauticas
  • 197
  • 1
  • 4
  • 20

1 Answers1

1

You have spaces in option string. I think thats the problem.

while getopts ":a:b:c:d:e:f:g:" opt; do

should sove your issue. Complete script like this

#!/bin/bash

while getopts ":a:b:c:d:e:f:g:" opt; do
case "${opt}" in

        a) FILETOPARSE=$OPTARG
           echo $compactAlarms
            ;;
        b) FILETOPARSE=${OPTARG}
           echo $nodeAlarms
            ;;
        c) FILETOPARSE=${OPTARG}
           echo $severityAlarms
            ;;
        d) FILETOPARSE=${OPTARG}
           echo $csvGentrator
            ;;
        e) FILETOPARSE=${OPTARG}
           echo $tableData
            ;;
        f) FILETOPARSE=${OPTARG}
           echo $help
            ;;
        g) FILETOPARSE=${OPTARG}
           echo $exit_function
            ;;
        *)
            echo "Error wrong Syntax,Opening help" && help
            ;;
    esac
done
sasubillis
  • 76
  • 5