Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to parse multiple long options? #13

Open
msabramo opened this issue Apr 15, 2022 · 2 comments
Open

Possible to parse multiple long options? #13

msabramo opened this issue Apr 15, 2022 · 2 comments

Comments

@msabramo
Copy link

msabramo commented Apr 15, 2022

I have this code:

while getopts_long ':remoteHost: toDir:' OPTKEY; do
    case ${OPTKEY} in
        'remoteHost')
            REMOTE_HOST="${OPTARG}"
            ;;
        'toDir')
            TO_DIR="${OPTARG}"
            ;;
        '?')
            echo "INVALID OPTION -- ${OPTARG}" >&2
            exit 1
            ;;
        ':')
            echo "MISSING ARGUMENT for option -- ${OPTARG}" >&2
            exit 1
            ;;
        *)
            echo "UNIMPLEMENTED OPTION -- ${OPTKEY}" >&2
            exit 1
            ;;
    esac
done

and I'm invoking my script with arguments: --remoteHost=somehost --toDir=/tmp/foo

The result is:

INVALID OPTION -- remoteHost

The result is the same if I use as arguments: --remote-host somehost --to-dir /tmp/foo

How do I specify that both --remoteHost and --toDir are valid long options?

@msabramo
Copy link
Author

msabramo commented Apr 15, 2022

Hmmm, it seems that it works as long as I have some short options also -- e.g.:

while getopts_long 'r:t: remoteHost: toDir:' OPTKEY; do

I guess the bug is that multiple long options don't work if you define no short options.

@billyzkid
Copy link

This works: while getopts_long ': remoteHost: toDir:' OPTKEY; do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants