linux switch 都可以传入什么类型,分别给出案例
时间: 2023-02-14 22:42:59 浏览: 62
Linux 的 switch 指令可以传入字符串或整数。
案例1 (字符串):
```
switch ($string) {
case "value1":
# code to be executed if $string == "value1"
break;
case "value2":
# code to be executed if $string == "value2"
break;
default:
# code to be executed if $string is not equal to any of the above
}
```
案例2 (整数):
```
switch ($number) {
case 1:
# code to be executed if $number == 1
break;
case 2:
# code to be executed if $number == 2
break;
default:
# code to be executed if $number is not equal to any of the above
}
```
注意:上述例子中的语言是bash 脚本语言.
阅读全文