1

I have a very basic script named colors to print "HEY" in green and bold using codes around the text.

colors:

#!/usr/bin/env python

a = '\033[0m\033[32m\033[01mHEY\033[0m'

print a

the \033[01m is making the text bold.

the \033[32m is making the text green.

the \033[0m should be around the text in both sides.

  • When I run the script on my machine - it prints in bold and green.
  • When I run the script on my machine with watch (watch -c colors) - it prints in bold and green.
  • When I run the script on a server via SSH - it prints in bold and green.
  • When I run the script on a server with watch and via SSH (watch -c colors) - in prints only bold.

I don't understand why the combination of the watch and doing it via ssh is making it print only bold and ignore the green. am I missing something?

What is the problem here?

lit
  • 14,456
  • 10
  • 65
  • 119
Ofek Agmon
  • 5,040
  • 14
  • 57
  • 101
  • maybe your `$TERM` is getting in the way? Check if it is set to a color-compatible value like `screen-256color` (if such applies) – user2722968 Apr 19 '17 at 12:22
  • in both my machine and the server the `$TERM` value is `xterm-256color` – Ofek Agmon Apr 19 '17 at 12:32
  • Can you try this in turn with two different machines to figure out on wich side of the connection the problem is? (As what you are doing should work, at least it does on my machine) – Fabian N. Apr 19 '17 at 13:27
  • 1
    You're right. it has something to do with this specific server. when connecting to my machine via ssh it worked. what in the server would make it not work? linux version? other things? – Ofek Agmon Apr 19 '17 at 16:05
  • Can you check the watch version on the server in question? `watch -v` (For reference: I'm currently on `procps-ng 3.3.10`) – Fabian N. Apr 20 '17 at 07:53
  • on the server `procps-ng 3.3.9`, on my machine `procps-ng 3.3.10`. I tried to look in the docs if they added something between the versions, couldn't find anything. you think its related? – Ofek Agmon Apr 20 '17 at 08:35
  • Can you show how exactly you run it over ssh (with and without watch)? For example, if you use ssh to login to the server and then run the program, it might run as expected. But if you use ssh with a remote command, you don't have a TTY attached by default and it will not show colours unless you use the -t switch with ssh. – kkeller Apr 22 '17 at 13:11
  • I first logged in with SSH, and then run the command, like you said, so the TTY should be attached. log in first (username/password) -> then run the command, still doesn't work – Ofek Agmon Apr 23 '17 at 07:25

0 Answers0