Sponsored Content
Full Discussion: Changing text colour in bash
Top Forums Shell Programming and Scripting Changing text colour in bash Post 302369482 by cfajohnson on Sunday 8th of November 2009 08:37:53 PM
Old 11-08-2009
Quote:
Originally Posted by TonyLawrence
Use "tput"

tput setaf 2

That doesn't work on at least one of the systems I use. There are two different versions of tput. One uses termcap, the other terminfo. They are not compatible.

On the other hand, the ISO 6429 standard (also known as ECMA-48, and formerly known as ANSI X3.64), is ubiquitous, and terminals that do not support it are few and far between.

Code:
green=$(printf "\033[32m")
normal=$(printf "\033[m")

Quote:

I honestly don't like colors for scripts.

Generally, I agree with you, but there are times when it is useful.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

HOw to change the text colour through shell script?

Hi all, I have written one script. If i run the script, particular text in that script needs to be displayed in color.how this could be done?any commands r there to change the colour of the text while running the script? Ur help is appreciated !!! Thanx in Advance, Sona. (7 Replies)
Discussion started by: Sona
7 Replies

2. UNIX for Dummies Questions & Answers

Need help with changing bash to perl

Hi guys, I am converting a bash script to perl. I need lots of help and pointers on how to make the script work. Any help would be greatly appreciated. Here is what I have: #!/usr/bin/perl #Decrypt Files $dir = "/usr/bin/gpg; opendir(PGP_DIR, $dir) || die "can't opendir $dir: $!";... (3 Replies)
Discussion started by: freak
3 Replies

3. Shell Programming and Scripting

bash changing file name

I want to run some unix commands on one file..let say if i change the name and that name of file is present already. I dnt want to change that presnt file but instead of that make another one with different name eg.. usa.txt if it is there make usa.txt.1 something like that Also one more... (5 Replies)
Discussion started by: Learnerabc
5 Replies

4. Shell Programming and Scripting

changing cron using bash script

How can I change the cron entries only for ABC and XYZ from dosomething_1.0.sh to nowchanged_2.0 using a bash script ? Any help will be appreciated. # # ABC 00,05,10,15,20,25,30,35,40,45,50,55 * * * * /mydir/dosomething_1.0.sh 1>/dev/null 2>&1 # # ## # DEF... (4 Replies)
Discussion started by: jville
4 Replies

5. Shell Programming and Scripting

Bash - changing a color of a substring

Hello! I need to write a bash script for my university classes, and I came up with an idea of a program that would test the speed of typing - there is some random text that you have to rewrite, and the script measures time, number of mistakes etc. The text would be visible on the screen all... (3 Replies)
Discussion started by: xqwzts
3 Replies

6. UNIX for Dummies Questions & Answers

Changing text in multiple files, but with different text for each file

Hello, I have a situation where I want to change a line of text in multiple files, but the problem is that I want to change the text to something unique for each file. For example, let's say I have five files named bob.txt, joe.txt, john.txt, tom.txt, and zach.txt. Each of these files has a... (5 Replies)
Discussion started by: Scatterbrain26
5 Replies

7. HP-UX

Changing default shell to bash

According to multiple sources you should not change the default shell to bash for the root user because it will make the system unbootable. Is there a safe way to launch bash for root when logging in? Perhaps I can edit /etc/profile or add it to a startup script somewhere? (2 Replies)
Discussion started by: bstring
2 Replies

8. Shell Programming and Scripting

Changing IFS in bash function

I have a function in bash that takes arguments. does IFS work in a function or does it apply only to the main script? (1 Reply)
Discussion started by: kristinu
1 Replies

9. Shell Programming and Scripting

awk and HTML with conditional text colour

Hello All, I am using awk with html options to format and send output to another file. Below command works fine, no issues. awk 'BEGIN{print "<table border="1" width="1000" >"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END {print "</table>"}' ${TMPLOGFILE1} >>... (0 Replies)
Discussion started by: jvmani_1
0 Replies

10. Shell Programming and Scripting

Changing from bash to ksh

Hello, I want to run a script written in ksh but my default shell is bash as root e.g in the script it has #!/bin/ksh i have gone into /etc/passwd to change it from :/bin/bash to /bin/ksh but still giving me an error when running scripts such as ./installer -bash: ./installer: /bin/ksh:... (3 Replies)
Discussion started by: DOkuwa
3 Replies
Xpm(3)							User Contributed Perl Documentation						    Xpm(3)

NAME
Image::Xpm - Load, create, manipulate and save xpm image files. SYNOPSIS
use Image::Xpm; my $j = Image::Xpm->new(-file, 'Camel.xpm'); my $i = Image::Xpm->new(-width => 10, -height => 16); my $h = $i->new; # Copy of $i $i->xy(5, 8, 'red'); # Set a colour (& add to palette if necessary) print $i->xy(9, 3); # Get a colour $i->xy(120, 130, '#1256DD'); $i->xy(120, 130, $i->rgb2colour(66, 0x4D, 31)); $i->vec(24, '#808080'); # Set a colour using a vector offset print $i->vec(24); # Get a colour using a vector offset print $i->get(-width); # Get and set object attributes $i->set(-height, 15); $i->load('test.xpm'); $i->save; # Changing just the palette $i->add_colours(qw(red green blue #123456 #C0C0C0)); $i->del_colour('blue'); DESCRIPTION
This class module provides basic load, manipulate and save functionality for the xpm file format. It inherits from "Image::Base" which provides additional manipulation functionality, e.g. "new_from_image()". See the "Image::Base" pod for information on adding your own functionality to all the Image::Base derived classes. new() my $i = Image::Xpm->new(-file => 'test.xpm'); my $j = Image::Xpm->new(-width => 12, -height => 18); my $k = $i->new; We can create a new xpm image by reading in a file, or by creating an image from scratch (all the pixels are white by default), or by copying an image object that we created earlier. If we set "-file" then all the other arguments are ignored (since they're taken from the file). If we don't specify a file, "-width" and "-height" are mandatory and "-cpp" will default to 1 unless specified otherwise. "-file" The name of the file to read when creating the image. May contain a full path. This is also the default name used for "load"ing and "save"ing, though it can be overridden when you load or save. "-width" The width of the image; taken from the file or set when the object is created; read-only. "-height" The height of the image; taken from the file or set when the object is created; read-only. "-cpp" Characters per pixel. Commonly 1 or 2, default is 1 for images created by the module; read-only. See the example for how to change an image's cpp. "-hotx" The x-coord of the image's hotspot; taken from the file or set when the object is created. Set to -1 if there is no hotspot. "-hoty" The y-coord of the image's hotspot; taken from the file or set when the object is created. Set to -1 if there is no hotspot. "-ncolours" The number of unique colours in the palette. The image may not be using all of them; read-only. "-cindex" An hash whose keys are colour names, e.g. '#123456' or 'blue' and whose values are the palette names, e.g. ' ', '#', etc; read-only. If you want to add more colours to the image itself simply write pixels with the new colours using "xy"; if you want to add more colours to the palette without necessarily using them in the image use "add_colours". "-palette" A hash whose keys are the palette names, e.g. ' ', '#', etc. and whose values are hashes of colour type x colour name pairs, e.g. "c => red", etc; read-only. If you want to add more colours to the image itself simply write pixels with the new colours using "xy"; if you want to add more colours to the palette without necessarily using them in the image use "add_colours". "-pixels" A string of palette names which constitutes the data for the image itself; read-only. "-extname" The name of the extension text if any; commonly XPMEXT; read-only. "-extlines" The lines of text of any extensions; read-only. "-comments" An array (possibly empty) of comment lines that were in a file that was read in; they will be written out although we make no guarantee regarding their placement; read-only. get() my $width = $i->get(-width); my ($hotx, $hoty) = $i->get(-hotx, -hoty); Get any of the object's attributes. Multiple attributes may be requested in a single call. See "xy" and "vec" to get/set colours of the image itself. set() $i->set(-hotx => 120, -hoty => 32); Set any of the object's attributes. Multiple attributes may be set in a single call; some attributes are read-only. See "xy" and "vec" to get/set colours of the image itself. xy() $i->xy(4, 11, '#123454'); # Set the colour at point 4,11 my $v = $i->xy(9, 17); # Get the colour at point 9,17 Get/set colours using x, y coordinates; coordinates start at 0. If the colour does not exist in the palette it will be added automatically. When called to set the colour the value returned is characters used for that colour in the palette; when called to get the colour the value returned is the colour name, e.g. 'blue' or '#f0f0f0', etc, e.g. $colour = xy($x, $y); # e.g. #123456 $cc = xy($x, $y, $colour); # e.g. ! We don't normally pick up the return value when setting the colour. vec() $i->vec(43, 0); # Unset the bit at offset 43 my $v = $i->vec(87); # Get the bit at offset 87 Get/set bits using vector offsets; offsets start at 0. The offset of a pixel is ((y * width * cpp) + (x * cpp)). The sort of return value depends on whether we are reading (getting) or writing (setting) the colour - see "xy" for an explanation. rgb2colour() and rgb2color() $i->rgb2colour(0xff, 0x40, 0x80); # Returns #ff4080 Image::Xpm->rgb2colour(10, 20, 30); # Returns #0a141e Convenience class or object methods which accept three integers and return a colour name string. load() $i->load; $i->load('test.xpm'); Load the image whose name is given, or if none is given load the image whose name is in the "-file" attribute. save() $i->save; $i->save('test.xpm'); Save the image using the name given, or if none is given save the image using the name in the "-file" attribute. The image is saved in xpm format. add_colours() and add_colors() $i->add_colours(qw(#C0C0DD red blue #123456)); These are for adding colours to the palette; you don't need to use them to set a pixel's colour - use "xy" for that. Add one or more colour names either as hex strings or as literal colour names. These are always added as type 'c' colours; duplicates are ignored. NB If you just want to set some pixels in colours that may not be in the palette, simply do so using "xy" since new colours are added automatically. del_colour() and del_color() $i->del_colour('green'); Delete a colour from the palette; returns undef if the colour isn't in the palette, false(0) if the colour is in the palette but also in the image, or true(1) if the colour has been deleted (i.e. it was in the palette but not in use in the image). EXAMPLE
Changing the -cpp of an image: my $i = Image::Xpm(-file => 'test1.xpm'); # test1.xpm has cpp == 1 my $j = $i->new_from_image('Image::xpm', -cpp => 2); $j->save('test2.xpm'); # Could have written 2nd line above as: my $j = $i->new_from_image(ref $i, -cpp => 2); CHANGES
2000/11/09 Added Jerrad Pierce's patch to allow load() to accept filehandles or strings; will document in next release. 2000/10/19 Fixed bugs in xy() and vec() reported by Pat Gunn. 2000/05/25 Fixed a bug in the test file; fixed a bug in save() which affected xpm extensions. 2000/05/04 Fixed bugs in xy(), vec(), save() and load(). Improved the test program. 2000/05/03 Created. AUTHOR
Mark Summerfield. I can be contacted as <summer@perlpress.com> - please include the word 'xpm' in the subject line. COPYRIGHT
Copyright (c) Mark Summerfield 2000. All Rights Reserved. This module may be used/distributed/modified under the GPL. perl v5.16.3 2000-11-09 Xpm(3)
All times are GMT -4. The time now is 05:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy