Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using su within a script

Status
Not open for further replies.

MaxPathan

Technical User
Aug 28, 2001
12
0
0
GB
Hi

I am running a script as root. The script uses su to ran some commands as another user in its environment. However I cannot seem to refer to the environment variables.

An example is shown below:


su - gri <<endgri
. moraenv HSGP apps # this sets the environment
echo $FSW_HOME # display the variable
env | grep FSW_HOME #
endgri

When the above is ran as root echo produces nothing, but the env command shows that FSW_HOME is set.

This is so puzzling. Does anyone know why i cannot access the environment variables when I su to another user?

Regards
Max
 
using 'su -' you're losing everything in the current shell ... can't be sure that 'su' will fix your problem, but might be worth a go ...

another fix, if you like, is to create a script file and get gri to run the script with '-c' ...
 
Thanks. Im using 'su -' because I need the env resetting to that users.
I will try the -c option.

Regards
Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top