【发布时间】:2014-10-03 17:06:42
【问题描述】:
Hi=("Hi" "Hello" "Hey") 行有可能的输入。我尝试在单词之间添加逗号,但这也不起作用。如果输入了 hi、hello 或 hey,我需要它来回显“Hi”。现在只有 Hi 有效。我想我正在寻找的是一种为一个词制作“同义词”的方法。用一个词代替另一个词的能力。
clear; echo
shopt -s nocasematch
echo; read -p " > " TextInput
Hi=("Hi" "Hello" "Hey")
if [[ "$TextInput" == $Hi ]]; then
clear; echo; echo
echo -e " >> Hi"
echo
else
clear; echo; echo
echo -e " >> Error"
echo
fi
我知道我可以使用
if [[ "$TextInput" == "Hi" ]] || [[ "$TextInput" == "Hello" ]] || [[ "$TextInput" == "Hey" ]]; then
但这会变得太长了。
【问题讨论】:
-
bash数组不适用于这种集合操作,因为它们是作为一种二级引用类型而不是作为容器类型开发的。
标签: linux bash if-statement multiple-conditions