LinuxQuestions.org
Help answer threads with 0 replies.
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 01-14-2009, 03:58 AM   #1
plebetan
Member
 
Registered: Jan 2009
Posts: 31

Rep: Reputation: 15
getting bash to use color


I always give the -ls option to get a color shell if i can. i.e. "bash -ls", "xterm -ls". i'd like to setup my .profile or .bashrc stuff so that this option is passed by default, so i can just execute "bash" or "/bin/bash" and still have a colorful shell. i've looked around for info on these to files, but it seems like they are mostly for running scripts and commands when bash starts. is there anyway to specify default options for bash?
 
Old 01-14-2009, 06:07 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Hi,

Take a look at .bashrc
 
Old 01-14-2009, 10:07 AM   #3
plebetan
Member
 
Registered: Jan 2009
Posts: 31

Original Poster
Rep: Reputation: 15
yeah, .bashrc seems to be able to configure colors and stuff for bash. but what "bash -ls" does(i think) is automatically guess the colors for a terminal. so really, i just want all of my bash sessions to run with a particular option.
 
Old 01-14-2009, 11:25 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
create an alias?
 
Old 01-14-2009, 12:21 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

You should setup a .bashrc & .bash_profile for your user;

Code:
sample .bashrc;
:~$ cat .bashrc

# Add bin to path

export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"

#export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40 gws

if [ `id -un` = root ]; then
   PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
 else
   PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi

#
# Add color
eval `dircolors -b`

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50 gws

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
   trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#   trap 0 rm -f ~$LOGNAME/.bash_history
Code:
sample .bash_profile;

~$ cat .bash_profile
# .bash_profile
#
# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
The .bashrc is very useful!
 
Old 01-14-2009, 06:35 PM   #6
plebetan
Member
 
Registered: Jan 2009
Posts: 31

Original Poster
Rep: Reputation: 15
so,
Code:
eval `dircolors -b`
turns on colors for ls output?

whats the difference between /etc/profile, ~/.profile, and ~/.bash_profile?

Last edited by plebetan; 01-14-2009 at 06:36 PM.
 
Old 01-14-2009, 06:55 PM   #7
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
Have a look at man bash under INVOCATION:
Code:
       When bash is invoked as an interactive login shell, or as a non-interactive shell  with  the
       --login  option,  it  first  reads and executes commands from the file /etc/profile, if that
       file exists.  After reading that file, it  looks  for  ~/.bash_profile,  ~/.bash_login,  and
       ~/.profile,  in  that  order, and reads and executes commands from the first one that exists
       and is readable.  The --noprofile option may be used when the shell is  started  to  inhibit
       this behavior.
       When  a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if
       it exists.

       When an interactive shell that is not a login shell is started, bash reads and executes com-
       mands  from  ~/.bashrc,  if  that  file  exists.   This may be inhibited by using the --norc
       option.  The --rcfile file option will force bash to read and  execute  commands  from  file
       instead of ~/.bashrc.
 
  


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
Color in bash shell zivota Linux - Newbie 6 12-06-2008 05:31 PM
Bash color shell L0CTiT3 *BSD 5 10-22-2008 11:59 AM
How can I change text color in BASH evansd321 Linux - General 1 09-10-2008 05:00 AM
bash diretory color raand Linux - Newbie 7 06-05-2008 05:32 AM
bash ls --color alias? tripmix Linux - Newbie 7 01-18-2005 05:49 AM


All times are GMT -5. The time now is 01:01 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