LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-16-2010, 07:34 PM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
Automate sourcing .bashrc when su - to root


I need to source the my /home/me/.bashrc file every time I "su -" to root. Is there any way to automate this? I cannot edit any thing in the root's environment as it is shared by people.

Thanks.

Last edited by noir911; 10-18-2010 at 04:52 AM.
 
Old 10-16-2010, 08:18 PM   #2
ndarkduck
LQ Newbie
 
Registered: Nov 2008
Location: Mex,Mex
Distribution: Fedora || Red Hat Linux
Posts: 28

Rep: Reputation: 7
uhm... usually /root/.bashrc has the answer for you, you may also look if you are using /root/.profile file, anyways. On the file that your shell is using, you may add
Code:
. /file/to/include.sh
Cheers
 
Old 10-16-2010, 08:55 PM   #3
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
What will it do if I include this: ". /file/to/include.sh" to my /home/me/.bashrc? And what's the content of the include.sh file?

Thanks.
 
Old 10-17-2010, 12:09 AM   #4
mesiol
Member
 
Registered: Nov 2008
Location: Lower Saxony, Germany
Distribution: CentOS, RHEL, Solaris 10, AIX, HP-UX
Posts: 731

Rep: Reputation: 137Reputation: 137
Hi,

it will do nothing. This was an example how to source a file. For your question change
Code:
/file/to/include.sh
to
Code:
.bashrc
in your case.

But .bashrc should be read automatically during logon.
From the bash manpage
Code:
When an interactive shell that is not a login shell is started, bash reads and executes commands from
~/.bashrc, if that file exists.
Possibly your .bashrc contains wrong or unusable code.
 
Old 10-17-2010, 05:16 AM   #5
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Sorry, I don't think you understand the problem.

When you log in, you get your .bashrc (/home/you/.bashrc). When you
"su -" to root you get root's .bashrc (/root/.bashrc). To overwrite root's bashrc with yours for that session, you type: ". /home/you/.bashrc" Now, I have to type this every time I su to root. And I was wondering how can I avoid typing this and automate this process.

Thanks.
 
Old 10-17-2010, 06:09 AM   #6
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS7
Posts: 267

Rep: Reputation: 58
If you do NOT use the "-", you do NOT get a login shell and your shell remains as it was, ie, the previous .bashrc of your shell remains. "-" is equivalent to "-l" see man su. Maybe that will work for you.
 
Old 10-17-2010, 07:28 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Given an interactive Bash login shell ('man bash': invocation) just add
Code:
RSRC="/home/you/.bashrc" [ -f "${RSRC}" ] && source "${RSRC}"
to the end of /root/bash_profile. Note it's not behaviour you would want to see on publicly accessible multiuser machines, just like the kernel doesn't read the firewall configuration but gets it pushed through the iptables binary, root should not read files owned by unprivileged users.
 
Old 10-18-2010, 04:51 AM   #8
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Thank you all for your reply. "su -m" was the option I was looking for.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sourcing .bashrc jbottiger Linux - Newbie 5 08-27-2010 12:56 PM
bashrc error, while sourcing linux_2010 Programming 3 07-13-2010 12:36 AM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
Sourcing .bashrc shifty_eyes Linux - Newbie 3 09-25-2005 09:43 PM
.bashrc error upon sourcing psiakr3w Linux - General 2 08-07-2004 12:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:43 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