I was asked by one of the SAP Basis engineers in my project team to create an environment variable for a specific user (psoadm). He wanted me to create a variable called SECUDIR and set it to /home/psoadm/sec, per the below:
SECUDIR = /home/psoadm/sec
So the first thing to do was find out the type of shell was being used. To do this I logged into the server as root and then ran:
su - psoadm
This allows me to switch user from root to the psoadm user and assume psoadm’s own home directory and environment variables – it’s the equivalent of psoadm logging into a new session.
To confirm the shell being used run the following:
ps -p $$
As you can see from the output below the shell was csh (C Shell):
PID TTY TIME CMD 7872 pts/0 00:00:00 csh
Now that we know that our shell is csh the next step is to add the SECUDIR variable to the following files: $HOME/.cshrc and $HOME/.login. The $HOME variable relates to psoadm’s home directory and is the equivalent of ~. So to edit the $HOME/.cshrc file run the following:
then scroll to the bottom of the file and add the following:
# Set SECUDIR for psoadm user setenv SECUDIR /home/psoadm/sec
Hit CTRL + x to exit and you will see the following:
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ? Y Yes N No ^C Cancel
enter Y to save and then it will ask to confirm the file to write these changes to, per the below:
File Name to Write: /home/psoadm/.cshrc
Hit Enter to confirm.
Now follow the exact same steps to update the $HOME/.login file. In order for the SECUDIR variable to be available you, either logout of the current shell and log back in or run the source command against the files, per the below:
source ~/.cshrc source ~/.login
Now enter echo $SECUDIR at the shell prompt like so:
And you will now see that the response correctly returns the value of SECUDIR as:
If your shell is bash, check the links directly below for advise on how to sent environment variables for the bash shell:
That’s all folks! I hope this was useful.