美文网首页
shell中的ps3以及select循环

shell中的ps3以及select循环

作者: 四阿哥萌萌哒 | 来源:发表于2019-10-23 23:56 被阅读0次

PS3作为select语句的shell界面提示符,提示符为PS3的值(赋予的字符串),更换默认的提示符”#?”

实例:

#!/bin/bash 
PS3="Select a program to execute:"
select program in '1s -F'pwd date 
do
  $program 
done

注意:ls -F 加的是单引号。

回馈

总结:PS3是一个和select循环语句结合使用的方式,在select语句后提示出要提示的语句。

以上脚本做个优化,加上exit跳出select循环。

select 是个无限循环,因此要记住用 break 命令退出循环,或用 exit 命令终止脚本。也可以按 ctrl+c 退出循环。

#!/bin/bash 
PS3="Select a program to execute:"
lelect program in 'ls -F'pwd date exit 
do
  $program 
done
反馈

相关文章

网友评论

      本文标题:shell中的ps3以及select循环

      本文链接:https://www.haomeiwen.com/subject/luilvctx.html