Operating System - HP-UX
1755751 Members
5040 Online
108837 Solutions
New Discussion юеВ

Something about shell scripting.

 
Thomas Boerner_1
New Member

Re: Something about shell scripting.

Hi,

at least on Linux there are two slightly different ways to submit the su command:

su $account
or
su - $account

The difference is that with "-" (means login) there will be a completely new environment whereas without the old environment will be used. I tried that:

tboerner@N01049LUX:~/Download > export MY_TEST_VARIABLE="Some dummy value"
tboerner@N01049LUX:~/Download > echo $MY_TEST_VARIABLE
Some dummy value
tboerner@N01049LUX:~/Download > su - tb
Password:

tb@N01049LUX:~ > echo $MY_TEST_VARIABLE

tb@N01049LUX:~ > logout
tboerner@N01049LUX:~/Download > echo $MY_TEST_VARIABLE
Some dummy value
tboerner@N01049LUX:~/Download > su tb
Password:
tb@N01049LUX:/home/nokia/Download > echo $MY_TEST_VARIABLE
Some dummy value
tb@N01049LUX:/home/nokia/Download > exit
tboerner@N01049LUX:~/Download > echo $MY_TEST_VARIABLE
Some dummy value

Hope that helps a bit to explain your question.
Have a nice day
W.C. Epperson
Trusted Contributor

Re: Something about shell scripting.

Kenny sed: "So you means that I can not pass exported variables after I use the su - command?? But why the same scripts in my other machines will work?? Do you have any clue about this??"
>>>
Kenny, apparently on the machines where things work, the environmental vars you need are being set globally at the start of each user shell (like from /etc/profile). Compare the /etc/profiles from a system where things work and from a system where things are broken, and you'll probably see what's happening.

"I have great faith in fools; self-confidence, my friends call it." --Poe
Klaus Crusius
Trusted Contributor

Re: Something about shell scripting.


I agree with Thomas, there is a difference wether you are using the "-" or not.
This is clearly documented on the man page of su. Unfortunately su has been withdrawn from the XPG and POSIX standards. That could explain diverging implementations on different OS. There is no difference between HPUX10 and HPUX11 with respect to the su man page.

Klaus
There is a live before death!