Option not recognized

梦想的初衷 提交于 2019-12-17 17:12:10

问题


I'm trying to use a case statement to determine if I have a legal command. It looks something like this:

function commandTest {
    case $1 in
    –score) echo "something";;
    *)      echo "unknown";;
    esac
}

Now if I use the function like this, it doesn't work. case doesn't recognize the string correctly although it is identical.

$ commandTest "-score"
unknown

What am I doing wrong here?


回答1:


As posted, your sample code has an en-dash (Unicode U+2013) in front of score, instead of a minus sign (ASCII 0x2D), which is preventing bash from matching the string -score

Switch:

–score) echo "something" 

to:

-score) echo "something" 


来源:https://stackoverflow.com/questions/20773530/option-not-recognized

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