|
|
How do I get my environment to come along when I "su"?A reader writes:
Here is the problem - when I su to become root I don't have any aliases or any stuff in my path. I also am not sure were the .bash_profile for root goes and if it is even read when su'ing - please help thanks.
This is an interesting puzzle. By default, when you use the sudo command, your environment should travel with you since it's just changing the effective user ID (or euid, if you want to be really geeky!). But su is another beast because it spawns a new subshell that should appear like it's from that account, not you. So shell aliases and environment settings are not typically inherited properly. Usually, though, people who work with su use either su - acct or su -l acct (depending on what flavor of Unix) which makes the subshell act as if it were a login shell, sourcing all "rc" files, and similar. That's probably what you want to use in this case.
In terms of where root has its "rc" files, the best way to ascertain that is to identify the HOME directory for the root account by using grep: grep root /etc/passwdQuite often, root has its home in the directory / or, sometimes, /home/root. You could then easily copy all of your own "rc" files into that directory to ensure that your root environment is functionally identical.
Related Unix and Linux Help articles:
✔ Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔ Shell script to convert lowercase to title case?As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
✔ Can I script renaming files based on an XML data map?I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing...
✔ Test for valid numbers in a Bash shell script?In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying...
✔ Review: iSSH for the iPad/iPhoneIf you're running an online business like I am, there are times when you need to connect and log in to the server...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
Categorized:
Unix and Linux Help
(Article 3688,
Written by Dave Taylor)
Tagged: Previous: And a nice review of "Wicked Cool Shell Scripts" Next: How do I tweak my PATH? Reader Comments To Date: 1
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help Find Me on Google+ ADT on G+ |
How do I get my enviroment to change back to my previous enviroment.