Sponsored Content
Top Forums Shell Programming and Scripting 'watch' not interpreting escape codes in bash script Post 302438364 by Arashi on Monday 19th of July 2010 12:35:46 PM
Old 07-19-2010
'watch' not interpreting escape codes in bash script

Hi there,

I'm fairly new to bash scripting and already having some troubles. I'm making a script that can print some series of strings in colors based in the information of a file, for simplicity let's say it only does:

Code:
#!/bin/bash
printf "\e[1;31;32m%-10s\e[00m" "OK"

When you execute this in the command line it prints a bold green 'OK'. So far so good.

Now, I need to check the output of the script over time using the command watch. The problem then arises. watch seems to ignore the escape codes and just prints:
Code:
[1;31;32mOK [00m

Is there any way to fix this?

If not, how can I check inside the script if it is being executed from a command? (watch in this case) So I can print without color for those cases.

Thanks for your time in advance!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

escape codes

I did a search and found the link for escape codes,- but I am not sure how to modify this script to set the margins. I started with a script that was already written on my system to set a printer to print landscape. I need to send an report that is in an ascii file to multiple printers from my... (1 Reply)
Discussion started by: MizzGail
1 Replies

2. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

3. Shell Programming and Scripting

bash awk codes to perl

Hi, I am interesting in writing the following bash codes into perl My script is simple take field 2 in /etc/passwd and put into an array #!/bin/bash PASSWD_FILE=/etc/passwd A=(`awk -F: ' { print $2 }' $PASSWD_FILE `) Can someone give me equivalent codes in perl ? (1 Reply)
Discussion started by: phamp008
1 Replies

4. UNIX for Dummies Questions & Answers

Using color escape codes in less

Hi all, Not sure how "for dummies" this question is, but I'd better use understatement... A. My Environment ============== I am using RedHat Linux, version 2.6.18-53.el5. When I type less --version I get: less 394 Copyright (C) 1984-2005 Mark Nudelman ... My terminal is configured... (1 Reply)
Discussion started by: Source2Exe
1 Replies

5. Ubuntu

rdiff-backup using escape codes on vfat thumbdrive

I thought it may be nice to use rdiff-backup to backup my websites to a thumb drive. But all the capital letters are substituted with octal escape codes. How can I over come this? There are no issues backing up to another ext3 drive. The source drive is ext3 the thumb drive is vfat mounted... (0 Replies)
Discussion started by: mikemc
0 Replies

6. UNIX for Advanced & Expert Users

CUPS printing and control escape codes

I ported application from SysV to Linux and run into troubles with printing. Application uses lp and HP JetDirect-based printers, it inserts HP control codes in the file and uses plain lp -d dest doc-file command to print it. The Linux (Ubuntu 8) has CUPS system, which I am not familiar... (0 Replies)
Discussion started by: migurus
0 Replies

7. Shell Programming and Scripting

Bash Shell Script Exit Codes

Here is my daily stupid question: How can I tell a script to only execute if the other scripts exits successfully? So "script A" executes and it executes successfully (0),then "script B" will run or else "script A "executes and it exits unsucessfully (1) then "script B" will read return... (6 Replies)
Discussion started by: metallica1973
6 Replies

8. Shell Programming and Scripting

Auto escape script to escape special chars in script args

This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters. For example, $ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh temp.mol.s temp.s It... (1 Reply)
Discussion started by: LMHmedchem
1 Replies

9. Shell Programming and Scripting

BASH - Propagation of error codes

Hello. I use bash functions which are in different script files. Theses scripts function files are sourced when necessary. As function does not easily return string value, Value are return using the echo function, and a return code is returned.. Now here my question : In the main script I... (11 Replies)
Discussion started by: jcdole
11 Replies

10. UNIX for Beginners Questions & Answers

Escape bash-special character in a bash string

Hi, I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies
WATCH(1)							Linux User's Manual							  WATCH(1)

NAME
watch - execute a program periodically, showing output fullscreen SYNOPSIS
watch [-dhvt] [-n <seconds>] [--differences[=cumulative]] [--help] [--interval=<seconds>] [--no-title] [--version] <command> DESCRIPTION
watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds; use -n or --interval to specify a different interval. The -d or --differences flag will highlight the differences between successive updates. The --cumulative option makes highlighting "sticky", presenting a running display of all positions that have ever changed. The -t or --no-title option turns off the header showing the interval, command, and current time at the top of the display, as well as the following blank line. watch will run until interrupted. NOTE
Note that command is given to "sh -c" which means that you may need to use extra quoting to get the desired effect. Note that POSIX option processing is used (i.e., option processing stops at the first non-option argument). This means that flags after command don't get interpreted by watch itself. EXAMPLES
To watch for mail, you might do watch -n 60 from To watch the contents of a directory change, you could use watch -d ls -l If you're only interested in files owned by user joe, you might use watch -d 'ls -l | fgrep joe' To see the effects of quoting, try these out watch echo $$ watch echo '$$' watch echo "'"'$$'"'" You can watch for your administrator to install the latest kernel with watch uname -r (Just kidding.) BUGS
Upon terminal resize, the screen will not be correctly repainted until the next scheduled update. All --differences highlighting is lost on that update as well. Non-printing characters are stripped from program output. Use "cat -v" as part of the command pipeline if you want to see them. AUTHORS
The original watch was written by Tony Rems <rembo@unisoft.com> in 1991, with mods and corrections by Francois Pinard. It was reworked and new features added by Mike Coleman <mkc@acm.org> in 1999. 1999 Apr 3 WATCH(1)
All times are GMT -4. The time now is 01:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy