LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2014, 08:58 PM   #1
AEDeGance
LQ Newbie
 
Registered: Oct 2014
Posts: 10

Rep: Reputation: Disabled
Why does .bash_color file fail to define colors?


Guys and Gals,

I've created a .bash_colr file to load some simple colors. It's just got lines like

Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow

etc. But when I do a ./.bash_colr the values of Black, Red, Green and Yellow are not fixed. For example, I do an echo "$Red" and get back a blank line. I want to create a file like the .bashrc file which is read by the .profile and defines the shell colors. Is the possible??
 
Old 10-23-2014, 10:06 PM   #2
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 384
Blog Entries: 2

Rep: Reputation: 96
Use
Code:
source ~/.bash_color
to load it.

Or
Code:
. ~/.bash_color
does the same thing.

Place one of those in your .bashrc
 
Old 10-23-2014, 10:52 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
"./" executes the file as a subprocess. Any variables (environment or not) that it creates will be lost as soon as it exits.

"." or "source" executes the statements in the file in the current process. Any variables that it creates will persist after it's done.

So if you want to keep the variables set up in the script, you would want to use ". ~/.bash_color" or "source ~/.bash_color", NOT "./.bash_color" or "~/.bash_color".

Last edited by suicidaleggroll; 10-23-2014 at 10:53 PM.
 
Old 10-24-2014, 10:37 AM   #4
AEDeGance
LQ Newbie
 
Registered: Oct 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you, most helpful. Your explanations, CoralFang and SuicidalEggroll, were good. I will be able to use the info elsewhere.

I have a second issue. If I execute . ~/.profile in an existing shell (which in turn invokes . ~/.bash_colr), everything works fine and the colors are defined in the shell. If, however, I click on the terminal window to start a shell, the colors are not defined. It's clear that . ~/,bash_colr was not executed by doing an echo "$Red". What might be going on?

Let me ask a follow up. When I do an 'env' in the shell (after .bash_colr has successfully run), the colors Red, Blue, etc are not listed in the env-vars. In a certain sense this makes sense since they are not define by 'set' but the question is, 'Where are they stored?' 'Where do I have access to them?'

Last edited by AEDeGance; 10-24-2014 at 11:37 AM.
 
Old 10-24-2014, 01:26 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
I believe .profile is only sourced once when you first log in, so for any changes to take effect you'll need to log out and back in.

.bashrc, on the other hand, is sourced every time you open a terminal, so if you put it there it would take effect the next time you open a terminal.

As for env, you're not creating environment variables, so they won't show up in env. If you want to make them environment variables you would need to put "export" in front, eg:
export Black='\e[0;30m'

Without export, they're just regular variables in the shell session, which means you will only have access to them within that shell. Subshells or subprocesses will not inherit the parent's regular variables, only environment variables.

Last edited by suicidaleggroll; 10-24-2014 at 01:27 PM.
 
1 members found this post helpful.
Old 10-24-2014, 02:39 PM   #6
AEDeGance
LQ Newbie
 
Registered: Oct 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
SuicidalEggroll, thank you for your expalantions. They were helpful.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I define a unique label in a #define macro? schmitta Programming 1 05-08-2014 08:23 AM
[SOLVED] how to define file type for wget golden_boy615 Linux - General 1 01-25-2011 09:16 AM
Too many file open - How can we define Max limit of file descriptor janeshb Linux - Server 11 09-29-2009 11:41 AM
how to define variables in the c file of kernel riquelme Programming 2 05-16-2004 08:42 PM
define file as a directory? canon Linux - General 4 03-19-2003 03:22 PM


All times are GMT -5. The time now is 06:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration