PS3
PS3
这个变量只存在于一个地方, 即select
选择的时候, 提示输入选择的内容:
ramesh@dev-db ~> cat ps3.sh
select i in mon tue wed exit
do
case $i in
mon) echo "Monday";;
tue) echo "Tuesday";;
wed) echo "Wednesday";;
exit) exit;;
esac
done
ramesh@dev-db ~> ./ps3.sh
1) mon
2) tue
3) wed
4) exit
#? 1
Monday
#? 4
默认的提示符是#?
.
然后我们更改一下:
ramesh@dev-db ~> cat ps3.sh
PS3="Select a day (1-4): "
select i in mon tue wed exit
do
case $i in
mon) echo "Monday";;
tue) echo "Tuesday";;
wed) echo "Wednesday";;
exit) exit;;
esac
done
ramesh@dev-db ~> ./ps3.sh
1) mon
2) tue
3) wed
4) exit
Select a day (1-4): 1
Monday
Select a day (1-4): 4
如果不在文件中更改的话, 也可以export
一下(还是用第一个未更改过的脚本):
➤ cat ps3.sh
select i in mon tue wed exit
do
case $i in
mon) echo "Monday";;
tue) echo "Tuesday";;
wed) echo "Wednesday";;
exit) exit;;
esac
done
➤ export PS3='yoooo--> '
➤ bash ps3.sh
1) mon
2) tue
3) wed
4) exit
yoooo--> 2
Tuesday
yoooo--> 4
➤