Last active
December 30, 2021 11:34
-
-
Save travishen/d68d158fba6a071c70fae88722703bd8 to your computer and use it in GitHub Desktop.
Classic Shell Script 範例- 選單項目與 select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh - | |
echo 'Select your terminal type:' | |
PS3='terminal? ' | |
select term in \ | |
'Givalt GL35a' \ | |
'Tsoris T-2000' \ | |
'Shande 531' | |
do | |
# 使用 case 語句來指定正確的值給 TERM 變量 | |
# 使用 REPLY 的值作為 case 選定器 | |
case $REPLY in | |
1) TERM=g135a ;; | |
2) TERM=t2000 ;; | |
3) TERM=s531 ;; | |
*) echo 'invalid.' ;; | |
# 如果值非法,break 語句不會執行,select 會重複提示循環 | |
if [ -n "$term" ] | |
then | |
echo TERM is $TERM | |
export TERM | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment