bash selcect循环的用法
语法:
[root@jay bash_practise]# help select
select: select NAME [in WORDS ... ;] do COMMANDS; done
eg:
#!/bin/bash
echo "which is ur favourite OS"
select os in windows linux iOS "Free BSD" other
do
echo "u have chosen $os"
done
执行结果:
[root@jay bash_practise]# bash 20230218select
which is ur favourite OS
1) windows
2) linux
3) iOS
4) Free BSD
5) other
#? 1
u have chosen windows
需要注意其中缺省的提示符是 #?
如果要进行修改,可以在脚本中定义PS3的值如下
#!/bin/bash
PS3="select ur os:"
echo "which is ur favourite OS"
select os in windows linux iOS "Free BSD" other
do
echo "u have chosen $os"
done
执行结果:
[root@jay bash_practise]# bash 20230218select
which is ur favourite OS
1) windows
2) linux
3) iOS
4) Free BSD
5) other
select ur os:1
u have chosen windows