“意外令牌附近有语法错误')'”?

时间:2018-10-24 13:55:38

标签: linux bash shell unix

echo "Which number port would you like to power up or down? 1, 2 or 3?"
read string
case "$string" in
    [1]* | [2]* | [3]*) echo "User entered: '$string'" ;;
    *) echo "I don't understand '$string'" ;;
esac

有人能阐明为什么这行不通吗? Bash的新手。

2 个答案:

答案 0 :(得分:0)

您确定没有“不可破坏的空间”(https://en.wikipedia.org/wiki/Non-breaking_space)吗? 例如在 *) echo

之间

答案 1 :(得分:-2)

我将其写为:

#!/bin/bash

echo "Which number port would you like to power up or down? 1, 2 or 3?"
read string
case "${string}" in
    [123]) echo "User entered: '${string}'" ;;
    *)     echo "I don't understand '${string}'" ;;
esac

在您的脚本1122中,依此类推也是有效的。