PS3

PS3这个变量只存在于一个地方, 即select选择的时候, 提示输入选择的内容:

  1. ramesh@dev-db ~> cat ps3.sh
  2. select i in mon tue wed exit
  3. do
  4. case $i in
  5. mon) echo "Monday";;
  6. tue) echo "Tuesday";;
  7. wed) echo "Wednesday";;
  8. exit) exit;;
  9. esac
  10. done
  11. ramesh@dev-db ~> ./ps3.sh
  12. 1) mon
  13. 2) tue
  14. 3) wed
  15. 4) exit
  16. #? 1
  17. Monday
  18. #? 4

默认的提示符是#?.

然后我们更改一下:

  1. ramesh@dev-db ~> cat ps3.sh
  2. PS3="Select a day (1-4): "
  3. select i in mon tue wed exit
  4. do
  5. case $i in
  6. mon) echo "Monday";;
  7. tue) echo "Tuesday";;
  8. wed) echo "Wednesday";;
  9. exit) exit;;
  10. esac
  11. done
  12. ramesh@dev-db ~> ./ps3.sh
  13. 1) mon
  14. 2) tue
  15. 3) wed
  16. 4) exit
  17. Select a day (1-4): 1
  18. Monday
  19. Select a day (1-4): 4

如果不在文件中更改的话, 也可以export一下(还是用第一个未更改过的脚本):

  1. cat ps3.sh
  2. select i in mon tue wed exit
  3. do
  4. case $i in
  5. mon) echo "Monday";;
  6. tue) echo "Tuesday";;
  7. wed) echo "Wednesday";;
  8. exit) exit;;
  9. esac
  10. done
  11. export PS3='yoooo--> '
  12. bash ps3.sh
  13. 1) mon
  14. 2) tue
  15. 3) wed
  16. 4) exit
  17. yoooo--> 2
  18. Tuesday
  19. yoooo--> 4