[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: need help with ~/.bash_profile
- From: gregory mott <gmott ntlworld com>
- To: redhat-list redhat com
- Subject: Re: need help with ~/.bash_profile
- Date: Sat Nov 2 09:24:07 2002
the shipped redhat(7.x) arrangement of bashrc's & profile's is confusing
and incorrectly documented. i evolved to this solution:
discard /etc/skel/.bash_profile before creating any users
replace /etc/profile and /etc/bashrc
i leave /etc/skel/.bashrc in place. it contains merely an invocation of
/etc/bashrc
similarly, my replacement /etc/profile merely contains an invocation of
~/.bashrc
for login shells, bash itself only invokes /etc/profile
for non login shells, bash itself only invokes ~/.bashrc
hence, in my setup, we get to /etc/bashrc in either case. the
simplicity of this avoids much confusion about which shell invocations
are like logins and which aren't. and i see no practical concern about
putting environment and function declarations all together.
otoh functions which in turn invoke aliases only work properly when the
file that defines them is conditionally invoked, not invoked if the
shell is not an interactive shell. so, in my setup, all my stuff is
actually in /etc/bashrc+, which /etc/bashrc only invokes in interactive
shells.
my actual files are included below.
Timothy Stone wrote:
> While I'm not a newbie with Linux (mostly abuse Apache and Java on my box) I take a lot of things for granted. One is how BASH works. It works most of the time.
>
> In fact I'm a TCSH convert to BASH. In RHL 7.3 BASH is the default shell, hence my conversion. But let me ask about the ~/.bash_profile, ~/.bash_login, etc. files. They don't seem to work.
>
> I have looked up all the documentation. The man pages state that ~/.bash_profile is read in turn with /etc/bashrc and ~/.bashrc but the ~/.bash_profile is disabled or just not being read. I have CLASSPATH settings for my shell in this file and have to manually source it with each new shell I use. Annoying.
>
> Is there something I'm missing here? Something that needs to be turned on? I saw a reference to BASH_PROFILE="TRUE" on one site but that didn't do the trick.
>
> Any help is greatly appreciated.
>
> Thanks,
> Tim
> /**
> * Timothy Stone . Sun Certified Java Programmer
> * Web Master . tstone at cityofhbg dot com
> * City of Harrisburg . 717.255.7297
> * Pennsylvania USA . 717.903.9162
> *
> * "This Satan's drink [coffee] is so delicious,
> * we shall cheat Satan and baptize it."
> * --Pope Clement VIII
> */
==> /etc/profile <==
# /etc/profile, only invoked for login shells, not by sulogin nor rsh nor su nor by subshell invocations.
# we simply call ~/.bashrc, bash calls there itself for non-login shells.
# put environment stuff in your .bashrc, that way changes are realized by merely starting a new bash.
[ $rctrace ]&&echo entering /etc/profile
. ~/.bashrc
[ $rctrace ]&&echo completed /etc/profile
==> /etc/bashrc <==
# /etc/bashrc, invoked via user ~/.bashrc
[ $rctrace ]&&echo entering /etc/bashrc
if [[ "$-" = *i* ]];then # are we an interactive shell?
for i in /etc/profile.d/*.sh;do
[ $rctrace ]&&echo $i next
[ -r "$i" ]&&. "$i"
[ $rctrace ]&&echo $i done
done;unset i
[ $rctrace ]&&echo /etc/X11/xinit/xinitrc.d/g next
. /etc/X11/xinit/xinitrc.d/g
[ $rctrace ]&&echo /etc/X11/xinit/xinitrc.d/g done
[ $rctrace ]&&echo /etc/bashrc+ next
. /etc/bashrc+
[ $rctrace ]&&echo /etc/bashrc+ done
fi
#functions using aliases only work if defined in files sourced only inside the above conditional
[ $rctrace ]&&echo completed /etc/bashrc
==> /etc/bashrc+ <==
# /etc/bashrc+, invoked via /etc/bashrc
ulimit -S -c 0
[ "$UID" = 0 ]&&umask 22||umask 2
alias funct=function
funct pathpref(){ echo :$PATH:|/bin/grep -q ":$*:"||export PATH="$*:$PATH";}
funct pathpost(){ echo :$PATH:|/bin/grep -q ":$*:"||export PATH="$PATH:$*";}
funct manpost(){ echo :$MANPATH:|/bin/grep -q ":$*:"||export MANPATH="$MANPATH:$*";}
Opath="$PATH"
pathpref /usr/bin
pathpref /usr/sbin
pathpref /bin
pathpref /sbin
pathpost /usr/local/bin
#pathpost /u/netatalk/bin
pathpost /usr/X11R6/bin
pathpost /usr/local/sbin
manpost /usr/local/man
#manpost /u/netatalk/man
[ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]&&export INPUTRC=/etc/inputrc
export TAPE=/dev/tape
export VERSION_CONTROL=numbered
export LESS='-i -R -z-3 --shift 20 -s -S -M -c'
alias so='((shopt;set -o)|sort)2>&1|t'
set -o notify
set -o noclobber
shopt -s histappend histverify histreedit dotglob nocaseglob extglob checkwinsize mailwarn
HISTSIZE=499
HISTFILESIZE=4499
HISTCONTROL=ignoredups
HISTIGNORE=j:f:-:h:l:L:ll:LL:lt:llt
FIGNORE='.TBL:~'
complete -d .
alias barc='source /etc/bashrc+'
alias scr='tty= screen -O -D -RR'
alias xfsstart='[ -f /var/lock/subsys/xfs ]||service xfs start'
alias vk-='xfsstart&&wm=$KDEDIR/bin/startkde vncserver -cc 3 -name kde -geometry 640x650'
alias vk='xfsstart&&wm=$KDEDIR/bin/startkde vncserver -cc 3 -name kde -geometry 800x600'
alias vg='xfsstart&&wm=gnome-session vncserver -name gnome -geometry 800x600'
alias xg='xfsstart&&xini xg /usr/bin/gnome-session'
alias xk='xfsstart&&xini xk $KDEDIR/bin/startkde'
funct xini(){ (for((x=0;x<=9;x++));do [ -e /tmp/.X$x-lock ]||break;done;rm -f /var/log/xx/$1:$x && xinit $2 -- :$x > /var/log/xx/$1:$x 2>&1 &);}
alias t=less
funct h(){ [ "$@" ]&&history "$@"||history 2>&1|t;}
alias j=jobs
alias b=bg
alias f=fg
funct r(){ %?"$*";}
alias pg='pgrep -f'
alias pk='pkill -f'
alias pk9='pkill -9 -f'
alias md=mkdir
alias mb='mv -bv'
alias ca='cp -ubav --sparse=always'
alias cf='cp -bav --sparse=always'
alias cx='cp -xa --sparse=always'
funct car(){ ca $2 $1;}
funct tarcopy(){ tar -cpSf - "$1"|tar -xpSf - -C "$2";}
#tar -cpSO --atime-preserve -C /source .|tar -xpSB --same-owner -C /target
funct tarx(){ tar -xpSf "$@";}
funct tarxj(){ tar -xjpSf "$@";}
funct tarxz(){ tar -xzpSf "$@";}
funct link(){ ln -sbv $2 $1;}
funct -~(){
#assignment from $1 drops \001 character, assign from $a instead
a=${a%%*(/)};[ ${a:0:1} = / ]||a=$(/bin/pwd)/$a
d=${a%/*}
a=${a##*/}
if cd "${d:-/}";then
fs=$(df .);fs=${fs##*% };b=$(/bin/pwd)/$a
b=${b##$fs*(/)}
b=$fs/$1/${b//\//\(}
n=$(($(ls -U1Nad "$b"~+([0-9]) 2>/dev/null|(echo -1;while read -r f
do echo ${f##*~};done)|sort -nr|head -n1)+1))
md -pm777 "$fs/$1";else false;fi;}
#- (with no args) same as %-
#- files tosses files into dumpster, moving aside anything of same name already in dumpster
funct -(){ if [ ! "$1" ];then %-;else (for a;do (-~ - &&(
[ -e "$b" -o -L "$b" ]&&(
mb -- "$b"{,~$n})
mb -- "$a" "$b"));done);fi;}
funct cb(){ a=$1;(-~ \~ &&
ca -- "$a" "$b"~$n);}
alias fixkonqtoolbar='- $KDEHOME/share/config/konq_history'
alias .=Cd
funct Cd(){ if [ "$*" == "" ];then cd;else cd "$*";fi;Nwd;Nld ldi;NLD;}
funct Nwd(){ export CWD=$PWD;}
funct Nld(){ if [ "$CWD" != "${ldirs[$*]}" ];then ldir="${ldirs[$*]}";fi;}
funct NLD(){ if [ "$CWD" != "${ldirs[0]}" ];then ldirs=("$CWD" "${ldirs[ ]}");fi;ldi=0;}
alias ,='((ldi+=(ldi<${#ldirs[*]}-1)));cd "${ldirs[ldi]}";Nwd;Nld 0'
alias ,,='((ldi-=(ldi>0 )));cd "${ldirs[ldi]}";Nwd'
alias ,0=' cd "${ldirs[ 0 ]}";Nwd;Nld ldi'
alias ,.=' cd "${ldirs[ldi]}";Nwd;Nld 0'
funct ..(){ Cd "$(dirname "$(/bin/pwd)")/$*";}
funct ...(){ Cd "$(dirname "$PWD" )/$*";}
alias cwd='echo pwd=$(pwd) /bin/pwd=$(/bin/pwd)'
alias listsort='sort -fs -k1.1,1.1' #listsort separates directories from files
alias La=' ls -alqF --full-time --color'
alias la=' La -v'
alias La.=' La -d'
alias la.=' la -d'
funct lla(){ la "$@" 2>&1|t;}
funct LLa(){ La "$@" 2>&1|t;}
funct l (){ la "$@"|listsort ;} #l sorts case distinct via ls -v
funct L (){ La "$@"|listsort ;} #L sorts case intermixed via g locale
funct ll (){ la "$@"|listsort 2>&1|t;}
funct LL (){ La "$@"|listsort 2>&1|t;}
funct l.(){ la. "$@"|listsort ;}
funct L.(){ La. "$@"|listsort ;}
funct ll.(){ la. "$@"|listsort 2>&1|t;}
funct LL.(){ La. "$@"|listsort 2>&1|t;}
alias lt=' la -tr'
funct llt(){ la -tr "$@" 2>&1|t;}
alias lt.=' la. -tr'
funct llt.(){ la. -tr "$@" 2>&1|t;}
alias ifsn="IFS=$'\n'"
funct finl(){ (ifsn;Lt "$@" $(find -type f))2>&1|t;}
alias listrunlevels='(La -d /etc/rc*.d/*|sort -f -k9.16 -k9)2>&1|t'
alias listconfig='(chkconfig --list|sort -fb -k2)2>&1|t'
alias listpkgs='rpm -qa|sort 2>&1|t'
alias psh='pshp|pshq 2>&1|t'
alias pshp='ps -eHo tty8,sess,tpgid,pgrp,ppid,pid,start,wchan,stat,args --cols 999'
funct pshq(){ (i=0;while read -r ps[i];do i=$((i+1));done;a=(1)
for((j=0;j<i;j=j+1));do pj=(${ps[j]}) #group together processes with same pgrp
if [ "${pj[4]}" = 1 ];then
for((k=j;k<i;k=k+1));do pk=(${ps[k]})
if [ "${pk[4]}" = 1 ];then
b=(${pk[ ]})
fi
if [[ "$pk" && "${b[3]}" = "${a[3]}" ]];then
echo "$(printf 'k%.3d' $k) ${ps[k]}"
ps[k]=
fi
done;pj=(${ps[j]})
fi
[ "${pj[4]}" = 1 ]&&a=(${pj[ ]})
[ "$pj" ]&&echo "$(printf 'j%.3d' $j) ${ps[j]}"
done);}
alias dfh='df -hT'
alias dfm='df -mT'
alias duff='diff -ubB'
alias grip='grep -i'
#findgrep "args to find in quotes" then args to egrep not in quotes
#findgrep: use -noleaf on dos filesystems
funct findgrep(){ find $1 -mount -type d \( -path /var -o -path /dev -o -path /tmp -o -path /home -o -path /root \) -prune -o -type f -print0|xargs -r -0 egrep -i "${@:2}";}
#unct findgrep(){ find ... -exec grep -i "$@" '{}' \;;}
alias showfetched='(cd /var/log;egrep "messages? for" $(ls -tr maillog*))2>&1|t'
funct st(){ (echo Return-Path: gmott igc org;echo Errors-To: gmott igc org;echo Subject: $@;echo To: $@;echo;echo just a test)|sendmail -t;}
funct mailnote(){ (echo Return-Path: gmott igc org;echo Errors-To: gmott igc org;echo Subject: $@;echo To: $LOGNAME )|sendmail -t;}
alias pow='um&&poweroff'
alias boo='um&&reboot'
alias um='.&&umount -atnfs,smbfs'
funct user(){ #adduser wrapper
adduser -Gstaff $1 &&
chmod 711 /home/$1 &&
md -p /v/h/samba/public/$1 &&
chown $1.staff /v/h/samba/public/$1 &&
link /home/$1/public ../../samba/public/$1 &&
smbpasswd -a $1 &&
passwd $1
}
funct userren(){ #change username
mb /home/$1 /home/$2 &&
mb /samba/public/$1 /samba/public/$2 &&
groupmod -n $2 $1 &&
usermod -d /home/$2 -l $2 $1 &&
sed -e "s|^$1:|$2:|" /etc/samba/smbpasswd >/etc/samba/smbpasswd%~ &&
cp -av /etc/samba/smbpasswd%~ >/etc/samba/smbpasswd
}
function useR(){ useradd -u0 -o -g$1 -d/home/$1/$2 $2&&passwd $2;} # useR patty pattY
#these are for comparing and merging into a new version
funct x(){ lt. /b1/~/*${1##*/} 0 /~/*${1##*/} 152;duff /b1/~/*${1##*/} 0 /~/*${1##*/} 152;}
funct x1(){ lt. /b1/~/*${1##*/}{ 0,} ;duff /b1/~/*${1##*/}{ 0,} ;}
funct x2(){ lt. /b1/~/*${1##*/} 0 $1 ;duff /b1/~/*${1##*/} 0 $1 ;}
funct x3(){ lt. /~/*${1##*/} 152 $1 ;duff /~/*${1##*/} 152 $1 ;}
funct xt(){ { lt. /b1/~/*${1##*/} 0 /~/*${1##*/} 152;duff /b1/~/*${1##*/} 0 /~/*${1##*/} 152;} 2>&1|t;}
funct x1t(){ { lt. /b1/~/*${1##*/}{ 0,} ;duff /b1/~/*${1##*/}{ 0,} ;} 2>&1|t;}
funct x2t(){ { lt. /b1/~/*${1##*/} 0 $1 ;duff /b1/~/*${1##*/} 0 $1 ;} 2>&1|t;}
funct x3t(){ { lt. /~/*${1##*/} 152 $1 ;duff /~/*${1##*/} 152 $1 ;} 2>&1|t;}
funct v(){ vim /b1/~/*${1##*/} 0 /b1/~/*${1##*/} $1 /~/*${1##*/} 152;}
ttywas="$tty";export tty=$(tty|cut -c 6-);[ "$shlv" == "" ]&&export shlv=-10
if [ "$shlid" != "$$" ];then
shlid=$$ ldirs=($PWD) ldi=0 PROMPT_COMMAND='history -s "($HISTFILE $(date "+%x %a %X" -r$HISTFILE 2>/dev/null||true)) $(date "+%x %a %X") $DISPLAY $WINDOW $tty $shlv";unset PROMPT_COMMAND'
if [ "$tty" != "$ttywas" ];then shlv=0;else ((shlv+=1));fi
fi
#COLOR_GREEN="\033[1;32m"
#COLOR_RED="\033[1;31m"
#COLOR_YELLOW="\033[1;33m"
#COLOR_NORMAL="\033[0;39m"
# ps='\$'
#if [ "$(id -u)" = "0" ];then
# PS="${COLOR_RED}"'\$'"${COLOR_NORMAL}"
#else
# PS="${COLOR_GREEN}"'\$'"${COLOR_NORMAL}"
#fi
#PS1=" $ps "
#PS1=" $PS\h$PS$tty$PS$shlv$PS\u "
#PS1=" $PS\h "
[ "$UID" = 0 ]&&PS1='#'||PS1='_';PS1=" $PS1$WINDOW$PS1$shlv$PS1$LOGNAME \h$PS1${DISPLAY:-$tty}$PS1\w$PS1 "
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]