Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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??
"./" 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 09:53 PM.
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?'
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 12:27 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.