shell 交互式选择(select)

 

新建文件

sudo vi test.sh

写入如下内容:

#!/bin/bash

echo "What is your favourite OS?"
select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
  break;
done
echo "You have selected $var"

赋予执行权限

sudo chmod +x test.sh

执行

./test.sh

 

输出:

What is your favourite OS?
1) Linux
2) Gnu Hurd
3) Free BSD
4) Other
#? 2
You have selected Gnu Hurd

 

posted @ 2018-12-04 01:06  anobscureretreat  阅读(1528)  评论(0编辑  收藏  举报