LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2018, 12:13 PM   #1
edomingox
Member
 
Registered: Mar 2009
Posts: 64

Rep: Reputation: 16
Keep persistent background color in bash script


I'm having a problem with background colors. I notice that when I do foreground colors, they are always persistent until you reset or change it. But I'm not getting the same results from background colors.

Here's an example of my background color value:

Code:
bBlack="\033[;40m"
bNC="\033[0;49m"      #resets
If I set the background to a color, then do a clear, it clears out the screen with said color. But as soon as I start outputting text or commands from the script, it goes back to the default background. Is there a way to set the color to black and have it persistent throughout the entire script?
 
Old 12-14-2018, 12:53 PM   #2
edomingox
Member
 
Registered: Mar 2009
Posts: 64

Original Poster
Rep: Reputation: 16
I think I figured it out. I found this: https://en.wikipedia.org/wiki/ANSI_escape_code

"All common sequences just use the parameters as a series of semicolon-separated numbers such as 1;2;3"

So, I realize that I can make the background black at all times by simply adding the color code in the right place, like this:

RED="\033[40;31m"

So setting the first sequence to a background color in conjunction with my foreground works.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Persistent persistent Persistent Going Nuts Here Fcukinyahoo Linux - Newbie 6 11-17-2011 09:56 PM
Will Deleting 70-persistent-cd.rules and 70-persistent-net.rules Work As a "Live USB" Konphine Linux - General 1 10-09-2011 03:55 PM
Screen App, Retain BG Color, Background color gets lost duerra Linux - Software 1 07-08-2009 03:01 PM
persistent static routes, not so persistent Hewson Linux - Networking 4 04-27-2007 05:09 PM
how change text (and background) color within the bash shell? Xavius Linux - Newbie 4 03-29-2004 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration