【问题标题】:What can I do to fix an error inside of case?我可以做些什么来修复案例内部的错误?
【发布时间】:2017-08-10 19:55:27
【问题描述】:

我的代码是:

-cname)
    changeName="{2}"

    if [ -z $changeName ]; then
        echo -en "Which note name do you want to change?"
        read -r $changeName
        echo "What would you like to change the name to?"
        read -r changeNewName
    if ! [ -z "${3}" ]; then
        echo "The name has to have no spaces."
        exit 1
    fi          
    if [ -f /usr/share/cnote/notes/$changeNewName ]; then
        echo "That note name is already used. Please choose a new one."
        exit 1
    fi
    cp "/usr/share/cnote/notes/${changeName}" "/usr/share/cnote/notes/${changeNewName}"
    ;;

如果我删除我的 case 语句的这一部分,它会再次起作用,但是在这部分我得到了那个错误: root@minibian:~/cnote# ./cnote -cname ./cnote:第 73 行:意外标记附近的语法错误 ;;' ./cnote: line 73: ;;'

【问题讨论】:

  • 你错过了一个fi,大概紧跟在read -r changeNewName之后。
  • shellcheck.net 在这种情况下非常有用

标签: linux bash shell scripting debian


【解决方案1】:

您的第一个 if 块未关闭。并且您不应该将 $ 符号放在 changeName 之前。所以第一部分一定是

if [ -z $changeName ]; then
    echo -en "Which note name do you want to change?"
    read -r changeName
    echo "What would you like to change the name to?"
    read -r changeNewName
fi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-13
    • 1970-01-01
    相关资源
    最近更新 更多