无法识别的选项 [英] Option not recognized

查看:116
本文介绍了无法识别的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用案例声明来确定我是否有合法命令.看起来像这样:

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
}

现在,如果我使用这样的功能,它将无法正常工作. case尽管相同,但不能正确识别该字符串.

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?

推荐答案

发布后,您的示例代码具有

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

切换:

–score) echo "something" 

收件人:

-score) echo "something" 

这篇关于无法识别的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆