Click to See Complete Forum and Search --> : Software:Bash:Overriding default aliases
jerbear
09-16-2003, 05:54 PM
I have RH8 and have been trying to set up a few aliases. Spefically, my .bashrc file currently reads:
# .bashrc
# User specific aliases and functions
alias la='ls -aF --color'
alias ls='ls -F --color'
alias ll='ls -alF --color'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
I have tried running "source .bashrc" but it doesn't change my aliases:
jdbrown@kitten jdbrown]$ alias
alias l.='ls -d .* --color=tty'
alias la='ls -aF --color'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
In other words, there seem to be some settings for ls and ll somewhere for which I am not able to override. The /etc/profile and /etc/bashrc files don't contain any alias commands. I do boot into xwindows, so I don't know if that affects anything. Any suggestions?
JB
mdwatts
09-16-2003, 06:11 PM
After making the alias changes, source the file as you have been doing and then type
alias
to see what they are set at.
jerbear
09-16-2003, 07:08 PM
That second quote is the output I get after sourcing the file and running alias. See the following:
[jdbrown@kitten jdbrown]$ cat .bashrc
# .bashrc
# User specific aliases and functions
alias la='ls -aF --color'
alias ls='ls -F --color'
alias ll='ls -alF --color'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[jdbrown@kitten jdbrown]$ source .bashrc
[jdbrown@kitten jdbrown]$ alias
alias l.='ls -d .* --color=tty'
alias la='ls -aF --color'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
There are other aliases and I'm not sure where they are specified. Also it won't let me override a couple of them.
Here is /etc/profile:
[jdbrown@kitten jdbrown]$ cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
pathmunge /usr/X11R6/bin after
unset pathmunge
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done
unset i
Here is /etc/bashrc:
[jdbrown@kitten jdbrown]$ cat /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -x /usr/bin/tput ]; then
if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal
stty erase `tput kbs`
elif [ -x /usr/bin/wc ]; then
if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb" terminal
stty erase `tput kbs`
fi
fi
fi
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
. $i
fi
done
fi
fi
# vim:ts=4:sw=4
Thanks,
JB
funnyjedi
09-16-2003, 09:35 PM
check the files in /etc/profile.d
especially /etc/profile.d/colorls.csh
Right.
Those aliases are being set by the /etc/profile.d/colorls.sh and /etc/profile.d/which-2.sh scripts, which are called from the following section of /etc/profile:for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi That little snippet basically says: "for every file which can be read in /etc/profile.d/, source that file".
One way to get around this would be to comment out the lines in those scripts which set the aliases you want to over-ride.
jerbear
09-17-2003, 04:02 PM
Yep, that took care of it! Makes sense too. Thanks a bunch! Now back to my printer issues. Grrr.
JB
Glad we could help you get it sorted (we'll be looking for that printer post).
;)
[SOLVED]
[Searching keywords]
alias source profile bashrc