Results 1 to 7 of 7

Thread: Resetting Terminal title (from shell script)

  1. #1
    Join Date
    Jul 2008
    Location
    Waterloo Canada
    Beans
    85
    Distro
    Ubuntu 14.04 Trusty Tahr

    Resetting Terminal title (from shell script)

    I have tried to change the terminal title a number of times in a (bash) shell script and I can't get it to work.

    I run a program that generates a lot of screen output and I'd like to see what stage the processing is at. In a Windows batch file I used to do:

    title "Solving the baseline"
    gams baseline
    title "Solving the first experiment"
    gams first

    I tried the following in a shell script, but it seems to do nothing.

    PS1="\[\033]2; Solving baseline $sc\007\] \h: "

    If I type that (literally) in terminal it works as I expect. (sc has been set)

    Thanks in advance.

    This is bash under Hardy Heron.
    Last edited by rwigle; September 24th, 2008 at 01:42 PM. Reason: Minor corrections plus added Ubuntu version.

  2. #2
    Join Date
    May 2007
    Location
    Portland, OR, USA
    Beans
    50
    Distro
    Kubuntu 8.04 Hardy Heron

    Re: Resetting Terminal title (from shell script)

    I don't think any environment variables set in a shell script will stick unless you source it.

    Try running "source script.sh" instead of "./script.sh". (alternatively you can try ". script.sh")

  3. #3
    Join Date
    Jan 2008
    Beans
    173

    Re: Resetting Terminal title (from shell script)

    Quote Originally Posted by rwigle View Post
    I have tried to change the terminal title a number of times in a (bash) shell script and I can't get it to work.

    I run a program that generates a lot of screen output and I'd like to see what stage the processing is at. In a Windows batch file I used to do:

    title "Solving the baseline"
    gams baseline
    title "Solving the first experiment"
    gams first

    I tried the following in a shell script, but it seems to do nothing.

    PS1="\[\033]2; Solving baseline $sc\007\] \h: "
    What you're trying to do depends, if possible, on which terminal emulator you're using. In any case, based on what you posted, doing
    Code:
    echo "\[\033]2; Solving baseline $sc\007\] \h: "
    will probably work.
    Member of the Planetary Society.

  4. #4
    Join Date
    Jul 2008
    Location
    Waterloo Canada
    Beans
    85
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Resetting Terminal title (from shell script)

    Thanks to both of you for trying, but what you suggested also doesn't work.

    (As asked this is gnome-terminal.)

    What I can't figure out is why my original attempt works if I type it in at an open gnome terminal, but not if I run a script with the exact same text in it. (Quoting, something?)
    Last edited by rwigle; September 26th, 2008 at 06:21 PM. Reason: clarification only

  5. #5
    Join Date
    Jan 2008
    Beans
    173

    Re: Resetting Terminal title (from shell script)

    Code:
    printf '\033]2;%s\007' "your_string"
    will work.

    The reason that setting PS1 works from the command line but not from a script is that BASH prints the output of PS1 as part of prompting. On the other hand when running a script BASH doesn't print PS1 at all so the content of PS1 is irrelevant. But that's not the full story. BASH interprets certain sequences of characters specially when they appear as part of PS1. I had forgotten about that in my previous reply. Have a look inside the BASH man page in the section titled "PROMPTING". So when prompting, BASH prints the output of the PS1 variable after interpreting those sequences. The end result is equivalent to the printf statement I gave above.

    Another thing to know is that gnome-terminal emulates the behaviour of xterm so for similar questions Google for "xterm escape sequences".
    Member of the Planetary Society.

  6. #6
    Join Date
    Jul 2008
    Location
    Waterloo Canada
    Beans
    85
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Resetting Terminal title (from shell script)

    That does it......

    I am just trying to port a bunch of batch files to shell files and learn as I go. So it's still a bit of greek to me....

    Also thanks re gnome-terminal=xterm (I thought so, but wasn't sure.)

  7. #7
    Join Date
    Mar 2007
    Beans
    2

    Re: Resetting Terminal title (from shell script)

    Quote Originally Posted by spibou View Post
    Code:
    printf '\033]2;%s\007' "your_string"
    will work.
    Thanks for the tip, very useful

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •