使用字符串的 shell 脚本内的动态标题
有人可以帮助我吗?我如何在shell脚本中创建标题,以便每次运行不同的报告时设置不同的标题..例如,如果有3个报告..Report1 Report2 n Report3..如何在shell脚本中自动更改标题,因此当Report1是运行它要说的 Report1,当运行 Report2 时标题会自动更改为 Report2 等等...
Can anyone help me?? how can i create title inside shell script so it set different title everytime i run different report.. for example if there are 3 reports.. Report1 Report2 n Report3.. how is it possible to change title automatically in shell script so when Report1 is run its going to say Report1 and when Report2 is run title automatically changes to Report2 and so on...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想显示“报告”,后跟计数变量的值,则使用 Bourne shell(Bash 等)等非常简单:
If you want to display "Report" followed by the value of a counting variable, it's really straightforward with, for instance, Bourne shell (Bash and others):
根据您告诉脚本运行report1、report2、report3的方式,您可以使用相同的方法来更改标题。
如果您执行“test.sh report1”来运行 1 并执行“test.sh 2”来运行报告 2,您可以这样做:
这当然省略了 report3,但仅对第三种情况使用 elif。
抱歉错过了一个右括号。
Depending on how you tell the script to run report1 vs report2 vs report3 you can just use that same method to change the title.
if you do "test.sh report1" to run 1 and "test.sh 2" to run report 2 you could do:
This is of course leaving out report3 but just use an elif for a third case.
sorry missed a closing bracket.
正如卡尔菲利普所说,您尚未具体说明标题的含义。
grantk 的答案设置了一个名为 TITLE 的变量。
ChrisJ 在控制台输出上显示报告名称。
我假设您正在使用 PuTTY 在远程系统上运行脚本,并且想要更改 PuTTY 窗口标题。
这是调整窗口标题和图标的一个很好的指南这适用于 PuTTY。
在您的情况下,在每个报告开头的某个位置,您可以使用以下命令设置标题:
假设您将输出发送到控制台,这应该会更改窗口标题。
尝试一下并告诉我。
As karlphillip has said you haven't specified what you mean by title.
grantk's answer sets a variable called TITLE.
ChrisJ's shows the report name on the console output.
I'm going to assume you are running your scripts on a remote system using PuTTY and want to change the PuTTY window title.
This is a good guide to adjusting the window title and icon and this works with PuTTY.
In your case somewhere at the start of each report you can set the title using:
and that should change the window title assuming you are sending your output to the console.
Give it a go and let me know.