【发布时间】:2018-06-09 21:22:47
【问题描述】:
我正在尝试编写一个循环的脚本,直到用户在列表中选择一个值(从0 到9 的单个数字)。这是我的 .sh 脚本,我尝试使用 sh 命令在 ubuntu 16.04 shell 中运行:
choice=999
echo $choice
until [[ $choice in 0 1 2 3 4 5 6 7 8 9 ]]
do
read -p "How many would you like to add? " choice
done
无论我做什么,我都无法让它发挥作用。这是一个测试,让您了解手头的错误:
sh test2.sh
999
test2.sh: 3: test2.sh: [[: not found
How many would you like to add? f
test2.sh: 3: test2.sh: [[: not found
How many would you like to add? 2
test2.sh: 3: test2.sh: [[: not found
How many would you like to add? 3
test2.sh: 3: test2.sh: [[: not found
How many would you like to add? r
test2.sh: 3: test2.sh: [[: not found
我尝试了很多东西:
- 避免使用
until并使用while - 只使用单数方括号
[ condition ],或者根本不使用方括号 - 使用
=~匹配正则表达式^[0-9]
没有任何作用。总是同样的错误。这是怎么回事? :(
【问题讨论】:
标签: linux list shell loops conditional-statements