#!/bin/bash
names=(
"张三"
"李四"
"王二"
)
echo "Please guess who is my friend :"
select var in ${names[@]}
do
if [ x$var = x"李四" ]; then #这里$var和"李四"前边的x,,是为了避免,当输入的选择不在select选项中(或$var为空),程序报错[: =: unary operator expected
echo "$var my good friend"
break
else
echo "Try again"
fi
done
知识点:
select用法,if 用法,break用法
用select编写简单的菜单选项