dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
576
share rss forum feed


Pjr
Don't Panic

join:2005-12-11
UK

Terminal Confusion

I have just discovered that when opening tty1 (CTRL + ALT + F1) and log in as root I have to use either su or . .bashrc to be able to use aliases defined in /root/.bashrc. Is this normal behaviour?

I don't believe this is the first time I've added an alias to /root/.bashrc in the 6 or 7 years I've been using Linux but I can't remember having to use su or . .bashrc before - hence the newbie question.

Every page I find on Google says RTFM but I have RTFMed both su and the invocation section in the bash manual and the more I read them the less I understand them.

--
Overflow error in /dev/null


timcuth
Braves Fan
Premium
join:2000-09-18
Pelham, AL

1 recommendation

Try .profile instead of .bashrc

Tim


Pjr
Don't Panic

join:2005-12-11
UK
Thanks for the reply; it worked with a little fiddling.

Summary: If I changed from user to root with su the alias could be used but with su - it couldn't.

Apparently .profile will only be acted upon if .bash_profile doesn't exist so I put it in .bash_profile and now have the same entry in both .bash_profile and .bashrc. Now the alias can be used regardless of whether I use su - or su

I have to assume that it's my ignorance of environments that is the problem. I need to find a Linux guide for the hard of thinking.

--
Overflow error in /dev/null


koitsu
Premium,MVM
join:2002-07-16
Mountain View, CA
kudos:23

1 recommendation

The issue you describe doesn't have to do with "environments" -- it has to do with the difference between what's called a login shell (vs. non-login shells) vs. interactive vs. non-interactive shells.

Read the bash man page for details (search for the term "interactive login shell" and read from there -- you will need to read a good 8 or 9 paragraphs worth).

This is what I use -- however, you should not use this method if you do silly things like call stty or tput or similar terminal-adjusting things in your dotfiles (those should go into .bash_profile exclusively, not .bashrc).

$ cat .bash_profile
# vim:ft=sh
 
if [ -f "${HOME}/.bashrc" ]; then
  source "${HOME}/.bashrc"
fi
 
# EOF
 

$ cat .bashrc
# vim:ft=sh
 
umask 077
 
# see strftime manpage
export HISTTIMEFORMAT="%T  "
 
alias dc='cd'
alias cp='cp -i'
alias mv='mv -i'
alias ps-='ps'
alias Tail='tail'
{...and lots of other stuff...}
 

Have fun.

--
Making life hard for others since 1977.
I speak for myself and not my employer/affiliates of my employer.


Pjr
Don't Panic

join:2005-12-11
UK

1 recommendation

Thank you for pointing out my misunderstanding(s), and for the examples and reading matter.

If those paragraphs are the same as the rest of the bash manual I'm sure I'll be back with more silly questions.
--
Overflow error in /dev/null