4

I added export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx to my .bash_profile, saved the file, then in terminal ran source .bash_profile and was able to see colors. However, upon closing the terminal and opening again, I saw that there were no colors even when the my .bash_profile is still the same.

EDIT: Using Terminal.app and bash

nukenine
  • 143

2 Answers2

4

Some terminals don't run a new login shell each time you open them so they are sourcing your .bashrc file instead of .bash_profile I would recommend putting your colors in the .bashrc file. Another solution that I probably wouldn't recommend but a lot of people do is to source your .bash_profile from within .bashrc

More info: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

jesse_b
  • 37,005
  • Thanks, but curious, why would you not recommend sourcing .bash_profile from within .bashrc? Also, according to that documentation, every new terminal window sources .bash_profile so shouldn't my situation be working? – nukenine Aug 04 '17 at 13:17
  • It just depends on what you put in your .bash_profile I guess. It's intended for trivial (probably not the right word) user preference/functionality modifications and could cause problems if it's sourced every time bash is called. For example you may want to create the following alias alias du="du -kh" which if put into the .bashrc file could cause some scripts to malfunction. – jesse_b Aug 04 '17 at 13:23
  • The documentation says that "if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt" The exception is mac's terminalx app which should source your .bash_profile but I'm guessing you are using something else. – jesse_b Aug 04 '17 at 13:25
  • 1
    @ron Because you should do the opposite: source .bashrc from .bash_profile. See https://unix.stackexchange.com/questions/192521/loading-profile-from-bash-profile-or-not-using-bash-profile-at-all/192550#192550 – Gilles 'SO- stop being evil' Aug 05 '17 at 23:24
  • @Gilles I've added source ~/.bashrc to my bash_profile but still no changes (exited Terminal and re-opened). I also tried if [ -s ~/.bashrc ]; then source ~/.bashrc; fi to no luck. – nukenine Aug 07 '17 at 12:19
  • @ron Please edit your question to indicate which terminal emulator and which shell you're using. Apparently you aren't using the default configuration. Is your ~/.bash_profile read at all? It is in the default configuration on macOS; most other configurations read ~/.bashrc when opening a terminal. Add set -x at the top of the file to make it print a trace of all the commands it runs, check that this appears on your terminal. – Gilles 'SO- stop being evil' Aug 07 '17 at 13:43
  • @Gilles Ok, I use Terminal.app and Bash, how would I tell if ~/.bash_profile is read? – nukenine Aug 07 '17 at 16:46
  • Add the following line to the bottom of your .bash_profile: echo "HEY! My bash profile is being read!" . You should see something like this at login: Last login: Mon Aug 7 10:50:50 on ttys000 You have mail. HEY! My bash profile is being read! joyentmac2252:~ jessebutryn$ – jesse_b Aug 07 '17 at 16:51
  • @Jesse_b @Gilles Ok I see it says at login: `'[' -s /Users/jeremy/.bashrc ']'
    • source /Users/jeremy/.bashrc

    ++ export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx ++ LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx`

    – nukenine Aug 07 '17 at 17:12
3

You need to set two environment variables in your ~/.bashrc file.

export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
Deathgrip
  • 2,566