What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

getop long options not work

pseu_asus

Occasional Visitor
Hi, all,
I have a simple script where I would like to use getopt long option, seems it can't work on ASUSwrt, do you have any idea?
Here is the simplified script:
Bash:
#!/usr/sh
args=$(getopt -l us,ca,mx,misc -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$args"
while :; do
case "$1" in
        --us)
            echo "us"
            shift;;
        --ca)
            echo "ca"
            shift;;
        --mx)
            echo "mx"
            shift;;
        --misc)
            echo "misc"
            shift;;
        --)
            echo "--"
            shift
            break
            ;;
        *)
            echo "??"
            shift
            ;;
esac
done

If I change the getop to "-o ucmo", then in the do case use the one-letter options, it works.
 
As far as I can tell to be able to use the long options it's mandatory to also define at least one short option (even if you ignore it).

P.S. Line 1 is an error. It should be #!/bin/sh

Code:
#!/bin/sh

args=$(getopt -l us,ca,mx,misc -o ucmo -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

eval set -- "$args"

while :; do
case "$1" in
        -u | --us)
            echo "us"
            shift;;
        -c | --ca)
            echo "ca"
            shift;;
        -m | --mx)
            echo "mx"
            shift;;
        -o | --misc)
            echo "misc"
            shift;;
        --)
            echo "--"
            shift
            break
            ;;
        *)
            echo "??"
            shift
            ;;
esac
done
 
Last edited:
Thank you. I'd seen this earlier today and haven't the chance to mess with it yet.

I recall the few times over the years that I've opted for "getopt" it was too arcane, and usually use "for i in $@; do case $i in; ....; esac; done" instead.

Gotta say that from the values of the options here, either a language or radio settings are the goal, and the latter really aren't useful these days...
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top