The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Some Info. ad4m88 UNIX for Dummies Questions & Answers 8 03-29-2008 07:01 PM
Need Info msgobinathan Shell Programming and Scripting 1 11-03-2007 05:17 PM
cpu info vijayca HP-UX 1 08-27-2007 08:51 AM
How get more LUN info itsupplies Red Hat 0 10-26-2006 04:22 AM
exe info sumsin High Level Programming 6 11-17-2005 05:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-19-2005
afflack afflack is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 5
SU info

from the man page of su:
EXAMPLES
Example 1: Becoming User bin While Retaining Your Previously
Exported Environment

To become user bin while retaining your previously exported
environment, execute:

example% su bin

Example 2: Becoming User bin and Changing to bin's Login
Environment

To become user bin but change the environment to what would
be expected if bin had originally logged in, execute:

example% su - bin

Found the info for my orig ques "what's the diff btwn su and su - when switching to root?"

I just don't understand it. Can anyone explain with an example of when to use su or su - when switching to root?

I have always just done "su" and I always see evryone else using "su -" when switching to root. ??
  #2 (permalink)  
Old 01-19-2005
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
If you login as root on console, you get root's environment set up - which may include more paths to commands/libraries/whatever.

If you su - root, it would be the same as logging in as root.

If you su root, you are only getting the priviledges of root, but the environment is yours, which may not include the correct paths to do some commands.

This is one example!
  #3 (permalink)  
Old 01-20-2005
afflack afflack is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 5
Any reasons for not just always using "su -"? Just one extra key. Why would you even bother using "su"?
  #4 (permalink)  
Old 01-20-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Quote:
Any reasons for not just always using "su -"? Just one extra key. Why would you even bother using "su"?
If you want to inherit the current shell we have to use su with out - ;
You will have subshell having all the previous environment.

When you do su - userid .., you will lose the current shell. it is equivalent to rlogin command. You will lose current shell environement.

See the following example.

$ export var1="hello"
$ echo $var1
hello
$ su user1
user1's Password:
$ echo $var1
hello
------------------> see var1 is retained to the new sub shell.
$ export var2="world"
$ su - user1
user1's Password:

$echo $var2

$

------------------> see var2 is NOT retained to the new shell.

Last edited by bhargav; 03-13-2005 at 02:22 AM..
  #5 (permalink)  
Old 01-20-2005
afflack afflack is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 5
Thanks - that really help's. Make sense now.

Thanks for the example.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0