LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-21-2006, 01:17 PM   #1
slackb0t
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware64-current on Thinkpad Carbon X1
Posts: 264

Rep: Reputation: 63
bashrc ??


Can someone show me your .bashrc config... I have heard of many possible tweaks. I have seen many bits and pieces of code but would love to see one that complete and elaborate etc...
 
Old 10-21-2006, 01:22 PM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
What kind of .bashrc (remember the dot in the beginning, it belongs to the filename)? .bashrc is basically just a file where you collect your aliases and stuff that you wish to be set every time you login, which bash then reads, so basically what you can and want to put in there is just about everything you can define using variables, aliases etc. in bash.

Like this: a simple basic .bashrc could be as follows:
Code:
alias ll="ls -al --color"
alias nautilus="nautilus --no-desktop"
alias aterm="aterm -fg white -tr"
export PS1='\u[\W]\$ '
export PAGER="most"
 
Old 10-21-2006, 01:32 PM   #3
liquidtenmilion
Member
 
Registered: May 2004
Location: South Carolina
Distribution: Slackware 11.0
Posts: 606

Rep: Reputation: 32
.bashrc contains any command you want to run when you launch any terminal. It should be used for setting aliases, setting environmental variables, or running daemons.

Here is my entire .bashrc file for an example.

Code:
anthony@Pismire:~$ cat .bashrc

# Set the values for some environment variables:
export MINICOM="-c on"
export MANPATH=/usr/local/man:/usr/man:/usr/X11R6/man
export HOSTNAME="`cat /etc/HOSTNAME`"
export LESSOPEN="|lesspipe.sh %s"
export LESS="-M"
export LC_ALL="en_US.utf8"
export XMODIFIERS=@im=SCIM
export GTK_IM_MODULE=xim
export QT_IM_MODULE=xim
export MPD_PORT="6600"
export MPD_HOST="Pismire"
export CFLAGS="-march=pentium3 -O2 -fomit-frame-pointer -fno-ident -pipe"
export CXXFLAGS="${CFLAGS}"
alias fbmplayer='mplayer -fs -x 800 -y 600 -zoom'

# If the user doesn't have a .inputrc, use the one in /etc.
if [ ! -r "$HOME/.inputrc" ]; then
  export INPUTRC=/etc/inputrc
fi

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games"

# For root users, ensure that /usr/local/sbin, /usr/sbin, and /sbin are in
# the $PATH.  Some means of connection don't add these by default (sshd comes
# to mind).
if [ "`id -u`" = "0" ]; then
  echo $PATH | grep /usr/local/sbin 1> /dev/null 2> /dev/null
  if [ ! $? = 0 ]; then
    PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
  fi
fi

# I had problems using 'eval tset' instead of 'TERM=', but you might want to
# try it anyway. I think with the right /etc/termcap it would work great.
# eval `tset -sQ "$TERM"`
if [ "$TERM" = "" -o "$TERM" = "unknown" ]; then
 TERM=linux
fi

# Set ksh93 visual editing mode:
if [ "$SHELL" = "/bin/ksh" ]; then
  VISUAL=emacs
#  VISUAL=gmacs
#  VISUAL=vi
fi

# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
 PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
 PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
 PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
 PS1='$ '
else
 PS1='\u@\h:\w\$ '
fi
PS2='> '
export PATH DISPLAY LESS TERM PS1 PS2

# Default umask.  A umask of 022 prevents new files from being created group
# and world writable.
umask 022

# Set up the LS_COLORS and LS_OPTIONS environment variables for color ls:
if [ "$SHELL" = "/bin/zsh" ]; then
 eval `dircolors -z`
elif [ "$SHELL" = "/bin/ash" ]; then
 eval `dircolors -s`
else
 eval `dircolors -b`
fi

# Notify user of incoming mail.  This can be overridden in the user's
# local startup file (~/.bash.login or whatever, depending on the shell)
if [ -x /usr/bin/biff ]; then
 biff y
fi

# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
  if [ -x $profile_script ]; then
    . $profile_script
  fi
done
unset profile_script

# For non-root users, add the current directory to the search path:
if [ ! "`id -u`" = "0" ]; then
 PATH="$PATH:."
fi

export PSPDEV="/usr/local/pspdev"
export PATH="$PATH:$PSPDEV/bin"
 
Old 10-21-2006, 01:46 PM   #4
slackb0t
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware64-current on Thinkpad Carbon X1
Posts: 264

Original Poster
Rep: Reputation: 63
I have stolen a few things from the .bashrc file now... but I would like to see more..
 
Old 10-21-2006, 05:23 PM   #5
aquaboogie90
Member
 
Registered: Jun 2006
Location: California
Distribution: Ubuntu 7.10
Posts: 33

Rep: Reputation: 15
I put these in my bash_profile:
Quote:
export PATH=$PATH:~/bin
alias cls="clear"
alias cp="cp -r"
alias bt="bittorrent-curses"
alias mp="mplayer"
alias untar="tar -xvf"
If you're constantly deleting things by accident at the command-line, maybe add
Quote:
alias rm="rm -i"
 
Old 10-22-2006, 02:10 PM   #6
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Perhaps the following will help:

Harmonizing the Bash Startup Scripts
 
Old 10-22-2006, 03:03 PM   #7
mdarby
Member
 
Registered: Nov 2004
Location: Columbus, Ohio
Distribution: Slackware-Current / Debian
Posts: 795

Rep: Reputation: 30
Here is mine (less personalized commands specific to my network)
Code:
. /etc/bash_completion

set -o emacs
set -b

ulimit -m 500000
ulimit -v 500000

export VISUAL=emacs
export EDITOR=emacs
export CVS_RSH=ssh
export HISTTIMEFORMAT="%y/%m/%d %T "
export HISTCONTROL=ignoredups
export PATH=$PATH:/usr/lib/jdk1.5.0_07/bin/
export PAGER="/bin/more"
export INPUTRC=~/.inputrc
export RSYNC_RSH=ssh

PS1="\u@\h:\[\e[31m\]\w\[\e[0m\]\$ "

#==== Misc Aliases ==================================
alias ..='cd ..'
alias b='cd -'
alias c='clear'
alias cl='clear && ls -l'
alias e='emacs-21.4-no-x11'
alias l='ls -l'
alias la='ls -Al'
alias ls='ls -hF --color'
alias lx='ls -lXB'
alias lk='ls -lSr'
alias lc='ls -lcr'
alias lu='ls -lur'
alias lr='ls -lR'
alias lt='ls -lhtr'
alias lm='ls -al | more'
alias hog='du -sk * | sort -rn'
alias hist='history'
alias install='./configure && make && checkinstall'
alias kernel='make bzImage modules modules_install'
alias mkdir='mkdir -p'
alias mm='multitail /var/log/maillog'
alias nsl='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2'
alias pg='ps aux | grep'
alias q='postqueue -p'
alias sc='screen -AR'
alias sl='slocate'
alias t='clear && tail -f -n 100'
alias tree='tree -A'
alias watch='watch -n1 -d'

#==== Work Aliases ==================================
alias rewind='mt -f /dev/nst0 rewind'
alias tell='mt -f /dev/nst0 tell'
alias status='mt -f /dev/nst0 status'
alias list_tape='tar -tv -b 128 -f /dev/nst0'

#==== Misc Functions ================================
RED='\e[1;31m'
BLUE='\e[1;34m'
CYAN='\e[1;36m'
NC='\e[0m'

function ii(){
    clear
    echo -e "\nYou are logged on ${RED}$HOSTNAME"
    echo -e "\nAdditional information:$NC " ; uname -a
    echo -e "\n${RED}Users logged on:$NC " ; w -h
    echo -e "\n${RED}Current date :$NC " ; date
    echo -e "\n${RED}Machine stats :$NC " ; uptime
    echo -e "\n${RED}Memory stats :$NC " ; free -m
    echo -e "\n${RED}Disk usage :$NC " ; df -lh
    echo -e "\n${RED}Local IP Address :$NC" ; /sbin/ifconfig eth0 | awk '/inet/ { print $2 } ' | sed -e s/addr://
    echo -e "----------------------------------------------------------------------\n"
}

function put_key(){
   if [ ! -s ~/.ssh/id_dsa.pub  ]
      then
         ssh-keygen -t dsa
   fi
   cat ~/.ssh/id_dsa.pub | ssh $1 'sh -c "cat - >> ~/.ssh/authorized_keys2"'
}

function fsize(){ du -s * | sort -g; }
function fis(){ grep -rsniH $1 $2; }

function strip_crap(){ 
    cp $1 $1~
    cat $1 | grep -v "^$" | grep -v ^# > $1  
}


function i() {
  if [ "$1" ]; then history 5000 | grep "$@"; else history 100; fi
}

function gen_certs(){
  mkdir /root/certs/
  cd /root/certs/
  /usr/bin/openssl genrsa -des3 -rand file1:file2:file3:file4:file5 -out server.key 1024
  /usr/bin/openssl rsa -in server.key -out server.pem
  /usr/bin/openssl req -new -key server.key -out server.csr
  /usr/bin/openssl x509 -req -days 60 -in server.csr -signkey server.key -out server.crt
  /usr/bin/openssl rsa -in server.key -out server.key
}

#====Work Functions==================================

work_server[0]=""
work_server[1]=""
work_server[2]=""

function servers(){
  for host in "${work_server[@]}"
    do
      scp $1 root@$host:$2
  done
}

function viruses(){
  cat /var/log/clamav.log | grep 'FOUND' | awk {'print $8'} | awk -F'-' '{print $1}' | sort -n | uniq -c | sort -rn
}
 
Old 10-23-2006, 03:32 AM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
Code:
# user added binds to special keys:
# <Alt>+w to show all possible completions for a command from history.
bind '"\M-w"':"\"\C-k\C-ahistory | grep '^ *[0-9]* *\C-e.'\C-m\""
It can be useful as a history search. You know you copied something but lost the links.
cp <Alt>+w brings up a list of cp commands from your history.
 
Old 10-23-2006, 08:16 AM   #9
sleepyEDB
Member
 
Registered: Dec 2005
Location: /USA/MI/Detroit/home
Distribution: MEPIS, antiX, RHEL
Posts: 105

Rep: Reputation: 15
Question

From Woodsman's link:

Quote:
~/.bash_profile: generally used to provide specific support related to logging in, and for local/personal environment variables and startup programs called only during the login process.


~/.bashrc: generally used for anything local/personal and peculiar to the user’s shell environment.
So, couldn't one customize the .bash_profile with the elements they want to be present when logging in, and then include the following in the .bashrc so that the same customizations are present when opening a new terminal?

Code:
source ~/.bash_profile

sleepy
 
Old 10-23-2006, 08:32 AM   #10
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
Normally it is the other way around: .bash_profile sources .bashrc
Code:
$ cat ~/.bash_profile
#!/bin/bash
# look for bashrc
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
Or am I missing your point?
 
Old 10-23-2006, 11:28 AM   #11
sleepyEDB
Member
 
Registered: Dec 2005
Location: /USA/MI/Detroit/home
Distribution: MEPIS, antiX, RHEL
Posts: 105

Rep: Reputation: 15
Thanks, muha.

No, i don't think you're missing the point. I was looking for the best way to have the customizations applied when logging in, and also when opening a new terminal.

On my current system, I have the .bash_profile customized, and the .bashrc set to source the .bash_profile file. My customizations are set when logging in, but when I open a new tab in my terminal (mrxvt), they are not. This may, however, have more to do with the config settings on my terminal that either the .bashrc or .bash_profile files.


sleepy
 
Old 10-23-2006, 02:12 PM   #12
oliv
LQ Newbie
 
Registered: Oct 2006
Posts: 22

Rep: Reputation: 15
Not closing applications when you close the terminal

The most annoying feature of bash if that it close all applications lauched from a terminal if you close this terminal. A work around is to add the following command to your .bashrc

PROMPT_COMMAND='disown -a -h'

Since I do not like the comportement of bash; I have patch it. After having applying my patch, you will see a new option (hupbgjobs, that you can set with with shopt). Bash then have the following, in my opinion more consistent behaviour:

if huponexit is unset; then application lauched from the shell will not be closed when you close the terminal, even if those applications are in the foreground.

if huponexit is set and hupbgjobs is unset; the applications launched from the shell are closed only if these are in the foreground (default behaviour of tcsh)

if huponexit is set and hupbgjobs is set; then all applications will be closed when the shell exit.

If anyone is interested, please email-me.
 
Old 10-23-2006, 02:19 PM   #13
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
@oliv: that sounds similar to screen's capabilities.
It can also keep processes alive even when you kill your bash.
 
Old 10-23-2006, 02:51 PM   #14
oliv
LQ Newbie
 
Registered: Oct 2006
Posts: 22

Rep: Reputation: 15
Quote:
Originally Posted by muha
@oliv: that sounds similar to screen's capabilities.
It can also keep processes alive even when you kill your bash.
I know screen; but its purpose is a little different; when you close the terminal the shell continue to run and you can resee it with reattaching. If you want to kill your bash you have explicitly to exit from it. If you have left screen in the background and kill it (killall screen); all applications launched from it will be killed.

What I want is that if a process run in the background, it continue to live whatvever I do with the xterm, the shell, screen, or so...
 
Old 10-30-2006, 09:37 AM   #15
slackb0t
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware64-current on Thinkpad Carbon X1
Posts: 264

Original Poster
Rep: Reputation: 63
need to see more .bashrc files... don't need so much commentary Just post your file
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
where is bashrc ? Kanaflloric Slackware 12 10-06-2007 02:47 PM
.bashrc hilljockey Debian 5 06-07-2006 01:11 PM
.bashrc roofy Slackware 7 05-06-2003 01:32 PM
bashrc nobu Slackware 6 03-21-2003 10:53 AM
.bashrc prasad Linux - General 1 04-14-2001 09:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:24 PM.

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