How do I correctly use getopt in a cshell script?

随声附和 提交于 2019-12-24 12:34:51

问题


Problem

I am trying to make a chshell script that takes in user input from several options. Inspired by this bash example, I tried to construct a while loop and switch case statement pattern around the getopt command. After several iterations I have tried to interpret this example from IBM:

set argv=`getopt :a:b:c:d:e: $*`

if ($? != 0) then
    exit 1
endif
while ({ ` $1 != --` })
    switch ($1)
        case[-a]:
            yada
            breaksw
        case[-b]:
            yada
            breaksw
        case[-c]:
            yada
            breaksw
        case[-d]:
            yada
            breaksw
        case[-e]:
            yada
            breaksw           
        default:
            yada default
            breaksw
     ends
end
shift

It returns the error: -a: Command not found.

Question

How do I correctly and efficiently use getopt in cshell without reinventing the wheel and essentially recopying the underlying getopt code?

来源:https://stackoverflow.com/questions/56399485/how-do-i-correctly-use-getopt-in-a-cshell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!