select菜单示例.sh Shell 脚本

Shell 片段 · codes/shell/逻辑控制/select菜单示例.sh · 15 行

源码

#!/usr/bin/env bash

PS3="Choose the package manager: "
select ITEM in bower npm gem pip
do
echo -n "Enter the package name: " && read PACKAGE
case ${ITEM} in
	bower) bower install ${PACKAGE} ;;
	npm) npm install ${PACKAGE} ;;
	gem) gem install ${PACKAGE} ;;
	pip) pip install ${PACKAGE} ;;
esac
break # 避免无限循环
done

查看上游源码 ↗

内容与示例整理自 dunwu/linux-tutorial,遵循 CC BY-SA 4.0;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。