0

i have the following code:

while getopts s:h:w:c:t:p option
do
        case "${option}"
        in
                s) CUSTOM_COMMSTR=${OPTARG};;
                h) CUSTOM_HOSTADDRESS=${OPTARG};;
                w) CUSTOM_WARNING=${OPTARG};;
                c) CUSTOM_CRITICAL=${OPTARG};;
                t) CUSTOMTYPE="${OPTARG}";;
                p) CUSTOM_PARTITION=${OPTARG};;
        esac
done

which generally works for me. my script runs like this:

./script.sh -s blah@h -h 127.0.0.1 -w 50 -c 60 -t -IFS -p /

when I run this script, it bails on the "-t -IFS". It complains that "illegal option I, illegal option F, illegal option S. I tried removing the "-" from the "-IFS" and still, no luck. I need to be able to pass multiple characters as is shown in my example. I googled getopts and I couldnt quite find a solution that addresses my exact problem.

can someone please help correct my problem?

OS: CentOS

EDIT:

this is not a duplicate. I'm asking about "getopts" not "getopt".

RoyMWell
  • 199
  • 1
  • 9
  • 1
    Possible duplicate of [getopt not accepting argument value starting with hyphen -](https://stackoverflow.com/questions/37784147/getopt-not-accepting-argument-value-starting-with-hyphen) – Michael Albers Jul 31 '18 at 03:13
  • 1
    @MichaelAlbers This isn't a duplicate; this question is about `getopts` (the shell builtin that ends with an "s"), that one's about `getopt` (and both answers suggest using `getopts` instead). But I can't duplicate it (under bash v3.2.57) -- it works for me as written. @RoyMWell I recommend testing to make sure nothing else in the script is messing it up, and that the characters between options on the command line are actually regular spaces, not something weird like non-breaking spaces. – Gordon Davisson Jul 31 '18 at 03:58
  • I get this error if there is no colon between t and p. – ctac_ Jul 31 '18 at 15:21

0 Answers0