Remotely setting putty window title

I have successfully used a script to modify putty's window title for many years. It has worked great in a Solaris 10 environment, using, sh, bash and tcsh. But I've never been able to get it to work in linux :frowning:

The script relies on sending escape sequences via gnu echo. The version of echo on both solaris and linux is exactly the same:

/bin/echo --version
echo (GNU coreutils) 5.97

The terminal client is putty 0.62, issued from a PC running Win7. The connection is via an ssh session.

For example, this works:

% /bin/echo "\033]0; JUST TESTING \007\c"

When it succeeds, nothing is echoed in the CLI session, and instead putty's window title changes to "JUST TESTING".

When if fails, it does nothing to putty's title, and instead echoes out this to the CLI session:

% /bin/echo "\033]0; JUST TESTING \007\c"
\033]0; JUST TESTING \007\c

I've tried, without success, all of these combinations (and more):

/bin/echo \\033]0\\; JUST TESTING \\007\\c
/bin/echo \\033]0\\; JUST_TESTING \\007\\c
/bin/echo \\033]0\\;JUST_TESTING\\007\\c
/bin/echo \\033]0\;JUST_TESTING\\007\\c
/bin/echo \033]0\;JUST_TESTING\\007\\c
/bin/echo "\033]0; JUST TESTING \007\c"
/bin/echo '\033]0; JUST TESTING \007\c'
/bin/echo \033]0\;JUST_TESTING\007\c
/bin/echo \033\]0\;JUST_TESTING\007\c
/bin/echo \\033]0\\;JUST_TESTING\\007\\c
/bin/echo \\\033]0\\\;JUST_TESTING\\\007\\\c

FWIW It works on the solaris system even if I first ssh to the linux system and then to the solaris system, so the packets are routed through the linux system on its way back to my PC.

Any ideas on how I can get this working would be greatly appreciated!

Thanks,
-Bob
Andover, MA US

echo's behavior with embedded escape sequences is inconsistent. Some don't expand escape sequences at all, some only do so when given -e, some do all the time. It gets worse -- since it's often a shell builtin, it's behavior may be different depending on the shell you use, even on the same system!

Linux's manual page for echo would have told you about the -e flag.

You should be using printf, which is nearly the same everywhere, and always handles escapes. Just add a \n onto the end of your strings and only give it one string. printf "\033]0; JUST TESTING \007\c\n"

Thanks for the tip on printf.

BTW I explicitly invoked /bin/echo so as to avoid any shell built-in echo. Furthermore, /bin/echo is the same version on both systems (i.e., gnu 5.97)

Also, I did check the manpage for echo, found the '-e' option and tried it. But it made no difference. I should have included that in the list of variations I tried!

Anyway, printf failed for me on the linux system, like this:

% printf "\033]0; JUST TESTING \007\c\n"
\c

(but it worked fine on the solaris system)

However, there is hope .. the printf on my solaris is version 8.10 from gnu coreutils, whereas it is an unknown version from the year 2006 on the linux system. I will upgrade printf and try it out.

thanks!

Translate "\c" into its octal equivalent and it'll work fine on printfs from 2012, 2006, or 1996...

1 Like

Using "\003" instead of "\c" makes it work like a charm .. even with the older printf.

Thanks for the help!