Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何在“case”中设置变量?_Bash_Shell - Fatal编程技术网

Bash 如何在“case”中设置变量?

Bash 如何在“case”中设置变量?,bash,shell,Bash,Shell,我遇到了一个错误,不确定出了什么问题 #!/bin/bash aa="boy" cc="1" case $cc in [1]* ) echo "You input 1";; aa="girl";; * ) echo "Please answer 1";; esac 错误: ./myscript: line 5: syntax error near unexpected token `;;' ./myscript: line 5: ` [1]* ) echo "You in

我遇到了一个错误,不确定出了什么问题

#!/bin/bash
aa="boy"
cc="1"
case $cc in
    [1]* ) echo "You input 1";; aa="girl";;
    * ) echo "Please answer 1";;
esac
错误:

./myscript: line 5: syntax error near unexpected token `;;'
./myscript: line 5: `    [1]* ) echo "You input 1";; aa="girl";;'
像这样的,

#!/bin/bash
aa="boy"
case $1 in
    [1]* )
        echo "You input 1"
        aa="girl"
        ;;
    * ) ;;
esac
echo $aa
输出为

$ ./test.sh
boy
$ ./test.sh 1
You input 1
girl
像这样的,

#!/bin/bash
aa="boy"
case $1 in
    [1]* )
        echo "You input 1"
        aa="girl"
        ;;
    * ) ;;
esac
echo $aa
输出为

$ ./test.sh
boy
$ ./test.sh 1
You input 1
girl
像这样的,

#!/bin/bash
aa="boy"
case $1 in
    [1]* )
        echo "You input 1"
        aa="girl"
        ;;
    * ) ;;
esac
echo $aa
输出为

$ ./test.sh
boy
$ ./test.sh 1
You input 1
girl
像这样的,

#!/bin/bash
aa="boy"
case $1 in
    [1]* )
        echo "You input 1"
        aa="girl"
        ;;
    * ) ;;
esac
echo $aa
输出为

$ ./test.sh
boy
$ ./test.sh 1
You input 1
girl

案例模式的结尾应该是一次,所以您必须使用;;每种图案只需一次

[1]* ) echo "You input 1"; aa="girl";;

您可以更改如图所示的行。

案例模式的结尾应为一次,因此您必须使用;;每种图案只需一次

[1]* ) echo "You input 1"; aa="girl";;

您可以更改如图所示的行。

案例模式的结尾应为一次,因此您必须使用;;每种图案只需一次

[1]* ) echo "You input 1"; aa="girl";;

您可以更改如图所示的行。

案例模式的结尾应为一次,因此您必须使用;;每种图案只需一次

[1]* ) echo "You input 1"; aa="girl";;

您可以更改行,如图所示。

[1]*)回显“You input 1”;aa=“女孩”(命令之间只有一个分号!)哦,我明白了,谢谢。我在电脑前坐的时间太长了。
[1]*)回显“You input 1”;aa=“女孩”(命令之间只有一个分号!)哦,我明白了,谢谢。我在电脑前坐的时间太长了。
[1]*)回显“You input 1”;aa=“女孩”(命令之间只有一个分号!)哦,我明白了,谢谢。我在电脑前坐的时间太长了。
[1]*)回显“You input 1”;aa=“女孩”(命令之间只有一个分号!)哦,我明白了,谢谢。我在电脑前坐的时间太长了。