开发者

Dynamic title inside shell script using string

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 automaticall开发者_运维问答y changes to Report2 and so on...


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):

#!/bin/sh

for i in 1 2 3
do
    echo "Report $i"
done


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:

if [[ $! -ne 1]] then
  TITLE="report1"
else
   TITLE="report2"
fi

This is of course leaving out report3 but just use an elif for a third case.

sorry missed a closing bracket.


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:

echo "\033]2;Executing Report 1\007"

and that should change the window title assuming you are sending your output to the console.

Give it a go and let me know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜