| ECS Home Automation and Security Archives |
| Subject: From: Date: | Re: [ecs] Fwd: linux questions Ingo Pakleppa Wed, 16 Feb 2005 17:05:51 -0800 |
su, by default, will reset the environment to a very basic one. It's pretty darn blank, I think the path may actually be a default compiled into BASH. -p prevents that, as you found out. A better one (in my opinion) is "su -". It will not preserve any environment variables, but rather will execute all the bashrc etc. files as if you had just logged in. As for the history that you asked about in your other post: I don't think there is a way, by design. With su, you don't just "switch" users, but rather you log on as a different user. That is, you get a new shell with its own history. As soon as you exit out of the su'd shell, you get the history back that you had as the user you were before. I suspect that not preserving the history may actually be intentional as it may be a security concern. It also flows from the system architecture. That said, you could probably theoretically copy the history. You'd have to copy the .bash_history file from your home directory to /root. I wouldn't do it, though. Instead, I would copy the command line to a file, and execute that. Note that you can get the echo statement without retyping easily with the up arrow and then editing the line. [ingo@sample]This is an annoyingly large command line that fails without root privileges Error: permission denied [ingo@sample]echo "This is an annoyingly large command line that fails without root privileges">~/x [ingo@sample]su - Password: root@sample#bash ~ingo/x root@sample#exit [ingo@sample] Mark Gilmore wrote: > I just discovered su's "-p" (preserve environment) argument (which > solves my PATH problem). > But I'm still curious to know just where "su" is getting it's PATH, less > this argument. > >> Date: Wed, 16 Feb 2005 16:03:05 -0800 >> To: ecs@netbloc.com >> From: Mark Gilmore <mark1@markgilmore.net> >> Subject: linux questions >> >> When I enter "su" to enter superuser mode, my PATH reverts back to >> some basic setting. >> This happens no matter *where* I put my PATH statement: >> /etc/profile >> /etc/bash.bashrc.local >> What gives ? >> >> Also, is there a way to use the *current* command history when >> entering superuser mode ? >> Here's what I do a gazillian times a day: >> Enter some long (hard-to-type) command >> Get an err (must be super user) >> "su" >> Hit up arrow (so as to recall the long cmd) and get squat >> Curse at the fact that the command history has changed !!!! >> Retype the command whilst grumbling >> >> tanx >> >> Mark Gilmore >> http://OmnipotenceSoftware.com > > > Mark Gilmore > http://OmnipotenceSoftware.com >