LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-22-2010, 12:15 AM   #1
pargoo
Member
 
Registered: Jan 2007
Posts: 39

Rep: Reputation: 0
getting aliases to work as root???


How can I get aliases working as root?
Here is my Slackware 13.1's /etc/profile file followed by my *Slackware 11's* /etc/profile file [as a comparison]. My Slackware 11's root aliases work in addition to my username ones *without* needing a separate .bashrc in my home dir.
In S13.1 I have created a .bashrc for my username and it works fine, but I want those same aliases operating when I'm root, and cannot for the life of me figure how to achieve it. Why???

S13.1 /etc/profile:

# /etc/profile: This file contains system-wide defaults used by
# all Bourne (and related) shells.

# Set the values for some environment variables:

export MINICOM="-c on"
export MANPATH=/usr/local/man:/usr/man
export HOSTNAME="`cat /etc/HOSTNAME`"
export LESSOPEN="|lesspipe.sh %s"
export LESS="-M"

# 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/games:/usr/sbin:/usr/local/sbin:/sbin"

# Let's try some aliases!!!!

alias l='ls -la|more'
alias cd='cd /home/pargoo'
alias start='/etc/rc.d/rc.inet1 restart'
alias stop='/etc/rc.d/rc.inet1 stop'


# 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 with the backspace key using 'eval tset' instead of 'TERM=',
# but you might want to try it anyway instead of the section below it. I
# think with the right /etc/termcap it would work.
# eval `tset -sQ "$TERM"`

# Set TERM to linux for unknown type or unset variable:
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

# 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 2> /dev/null
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

...And my Slackware 11 /etc/profile:


# /etc/profile: This file contains system-wide defaults used by
# all Bourne (and related) shells.

# 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"

# Set a few aliases (hopefully!!)

alias l='ls -la|more'
alias p='cd /home/pargoo'
alias start='/etc/rc.d/rc.inet1 restart'
alias stop='/etc/rc.d/rc.inet1 stop'


# 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 with the backspace key using 'eval tset' instead of 'TERM=',
# but you might want to try it anyway instead of the section below it. I
# think with the right /etc/termcap it would work.
# eval `tset -sQ "$TERM"`

# Set TERM to linux for unknown type or unset variable:
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

# 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 2> /dev/null
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

I have searched for days for a solution and it is extremely annoying to be baulked by such a small glitch. All help appreciated!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 08-22-2010, 03:11 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,370

Rep: Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335
Haven't we gone to /etc/profile.d/ for all settings?
Stick the aliases there.
 
Old 08-22-2010, 05:02 AM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,153

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Either copy your .bashrc to roots home folder or make a symlink a symlink would be best as then any changes made in your .bashrc would be reflected in roots
 
Old 08-22-2010, 08:16 AM   #4
pargoo
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 0
<takes deep breath>
Okay, here's the state of play. Before the last time I shut my machine down I created a .bashrc file in my home dir with just a few simple aliases like l='ls -la|more' and - lo and behold, they worked as long as I was in a user-terminal. Thinking the battle was half-won, I commented out all the identical aliases in /etc/profile. Imagine my surprise when I reopened a fresh konsole as user to find 'l' now got a 'command not found' error.
What?????
I then renamed my ~/.bashrc to ~/notworking.bashrc and returned as root to my /etc/profile file and un-commented aliases one by one. Every time I opened a fresh terminal as user the particular alias I had just uncommented now worked thus proving to my satisfaction that IT was setting my user-specific aliases, NOT my ~/.bashrc file [which, as you may recall, I had renamed].
I then created a .bashrc file with those same simple aliases and put it in /etc/profile.d. Guess what: my user aliases were still okay but *still* no aliases at all for root, which is what this is all about. I also renamed it /etc/profile.d/bashrc to see if the '.' made any difference. It didn't. I see by a scrap of paper I scribbled notes down on that /etc/profile.d/bash_profile didn't work either.
 
Old 08-22-2010, 08:30 AM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Perhaps the difference is whether or not the particular shell (xterm, VT, konsole, whatever) is a login shell or not. Bash reads different files when it is invoked as a login shell or not. Check the man-page for details. Note that by default, virtual terminals are login shells already - but your X terminals may or may not be.

Meanwhile, try in a xterm starting bash (as either user or root) like:
Code:
bash -l
and see if aliases and things which do not work previously, do work now?

FWIW, I made wrapper scripts to start my x-terminals, and made them always start bash with -l thereby saving me this hassle.
 
Old 08-23-2010, 10:05 AM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,153

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by GrapefruiTgirl View Post
Perhaps the difference is whether or not the particular shell (xterm, VT, konsole, whatever) is a login shell or not...
Bash reads different startup files like this:
Login shell (ie the virtual consoles ) 1st looks for /etc/profile (NOT /etc/profile.d/profile) if that file can't be found then looks for ~/.bash_profile, ~/.bash_login, and ~/.profile as per the man page.

For non login interactive shells ie most x terminals looks for ~/.bashrc it doesn't look in /etc/ or /etc/profile.d automatically if you want to put a bashrc file in etc for use globally you must specifically include it from your ~/.bashrc ie:
Code:
if [ -f /etc/bashrc ] ; then
  . /etc/bashrc
fi
I admit it's really confusing where bash reads its startup files from but if in doubt try the man pages
May be something like thius could be made a sticky as I seem to recall a number of posts on similar subjects?

Last edited by Keith Hedger; 08-23-2010 at 10:06 AM.
 
Old 08-23-2010, 10:19 AM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I agree, a sticky *might* be a good idea - or at least, a good tutorial/article on the subject somewhere that we could point to.

A while back, for diagnostic purposes, I put a line at the top of all my .profile and .*bash* files which would print what file it was when it was read. This was very helpful in figuring out why I had been having similar issues as the OP.
 
Old 08-23-2010, 11:14 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Keith Hedger View Post
Bash reads different startup files like this:
Login shell (ie the virtual consoles ) 1st looks for /etc/profile (NOT /etc/profile.d/profile) if that file can't be found then looks for ~/.bash_profile, ~/.bash_login, and ~/.profile as per the man page.
If "ie" was used to mean "that is" (as opposed to "for example") then that is not the whole story; login shells can be started from other places apart from the virtual terminals such as logging on graphically, over a network, at a serial line terminal and when forced by the -l option.

Regards "if that file can't be found", here's from the GNU Bash Reference Manual (my bolding): "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".
 
Old 08-23-2010, 11:52 AM   #9
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,153

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Sorry I meant eg not ie yes you are right I misread the man the other profile files seem to be for adding extra per user stuff, it's been a very bad day today I'm going to go away now and be very quiet, apologies
 
Old 08-23-2010, 01:10 PM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
A helpful article on the subject...

Woodsman once wrote an excellent article on this subject here: Harmonizing the Bash Startup Scripts

Worth bookmarking!
 
3 members found this post helpful.
Old 08-23-2010, 01:36 PM   #11
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,153

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by astrogeek View Post
Woodsman once wrote an excellent article on this subject here: Harmonizing the Bash Startup Scripts

Worth bookmarking!
Excellent link very succinct and easy to follow all newbies should have a read ( and oldies come to think of it ! )
 
Old 08-23-2010, 01:41 PM   #12
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by astrogeek View Post
Woodsman once wrote an excellent article on this subject here: Harmonizing the Bash Startup Scripts

Worth bookmarking!
I accidentally stumbled on this post and found it to be very useful !! Thanks to you
 
Old 08-25-2010, 04:01 AM   #13
pargoo
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 0
Have been away for three days, hence the slow reply.
I tried "#bash -l", and yes, my aliases start working as root. Close the window and open another one and they don't work again - I have my shortcut in KDE ticked as 'run as different user' - root, obviously, if this means anything important(?) If I type "exit" as root it says "logout" and I'm back to aliases not working even though I'm still root.
At least I have a short-term fix!
 
Old 08-25-2010, 06:10 AM   #14
pargoo
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 0
P.S: I also notice that after typing 'bash -l' my prompt now lists the active dir the way I want it to: root@pargoo:/etc/X11#
Never knowing where I am and having to enter 'pwd' all the time is a PITB.
 
Old 08-25-2010, 09:45 AM   #15
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Keith Hedger View Post
Sorry I meant eg not ie yes you are right I misread the man the other profile files seem to be for adding extra per user stuff, it's been a very bad day today I'm going to go away now and be very quiet, apologies
No worries, no problems and don't be a stranger

We all make mistakes (I make lots -- as a search of my post for "Oops" shows) and anyone who never risks making a mistake doesn't get far. That's one of the great things about this community -- if someone makes a mistake, mostly someone corrects it soon afterwards and greater knowledge is gained.
 
  


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
Apache - when I make aliases to folders outside of main Doc. root Access Forbidden yogi799 Linux - Software 1 06-09-2009 10:43 AM
Root Aliases carlosinfl Linux - Server 2 11-29-2007 10:11 AM
ip aliases not work outside same netmask hkj Linux - Networking 2 05-14-2006 08:17 AM
Can't get mail aliases to work properly npinney Linux - General 5 08-25-2005 03:51 AM
bashrc Aliases don't work soren625 Linux - Newbie 10 01-27-2005 08:59 AM

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

All times are GMT -5. The time now is 07:26 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
Open Source Consulting | Domain Registration