分类: 系统运维
2013-01-31 10:40:46
一般我们写多分支选择语句 都会用
case $1 in
……
;;
esac
偶然发现 select写多分支语句其实也很方便
eg:
#!/bin/bash
echo "what is your favourite OS?"
select var in "Windows" "Linux" "MAC"
do
if [ $var = Windows ]
then
Your favourite OS is $var
elif [ $var = Linux ]
then
Your favourite OS is $var
elif [ $var = MAC ]
then
Your favourite OS is $var
fi
done
其实上面这个脚本完全不需要如何复杂的来写,之所以加了if……then……elif……then……fi,主要是想再熟悉了if句式的写法。