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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating variable in Solaris

Status
Not open for further replies.

tomecki24

Programmer
Jun 13, 2001
52
DE
Hello,

I would like to have a new environment variable.
I used command:
export MYVAR=/usr/bin;

It worked and I could check it witn env command.
But when I closed terminal windows and started it again, there was no MYVAR variable. How can I make it always visible.

I'm working on Solaris 7, bourne and korn shell.

Thanks
Tomasz
 
Put the command in your .profile file in your home directory.

Greg.
 
Ok but I don't have .profile file in my home directory. How it should look like? What is the structure of that file?
What about CLASSPATH variable? I would like all users could have the same. How should I do that?

Thank You very much.
Tomasz
 
It doesn't need to "look" like anything. It's just a file of commands which gets executed whenever you log in. If you don't have one in your home dir (i.e. the directory you are placed in when you log in) then you just need to create the .profile file. An example file might look like -
Code:
# standard variables
PS1='$PWD >'
PATH=$HOME:/usr/bin:/usr/local/bin:.
export PS1 PATH

# personal settings
MYVAR=/usr/bin
CLASSPATH=/usr/class/whatever
export MYVAR CLASSPATH
Once you've created the file, make sure you have execute permission granted on it.

If you have any questions I'll be happy to have a go at helping.

Greg.
 
Also, check out the manual page (do a man profile).

Greg.
 
Great! thanks, it works now. I'm new in Solaris (Unix) system but I have to know it well very quickly.

If You don't mind, I've got another questions:
1. Where is .profile file for root?
2. How to create a variable (for example CLASSPATH)
available for all users (not only for me)?

Thanks
Tomasz
 
First of all There is a file is called /etc/profile, if do not create any, profile then your using what ever in /etc/profile. (default)

if your a user ( $) and your Shell is Bourne Shell, your profile it will .profile.
If your using Ksh, your profile it will be .Kshrc.
If Your a root and using Bourne Shell (SH) your profile it will be .profile. As well as if your using ksh your profile it will be .kshrc.

I think this it will help you.
F. Regal
 
Hi,

Thanks everyone here but still I've got no answer how to set up variable available for ALL users (in Windows: system variable, not user variable).

Thanks
Tomasz
 
Tomasz,
in the aforementioned /etc/profile (which is the profile for every user) just put in the variable settings in the following form:
<varName1>=<initValue1>
<varName2>=<initValue2>
<varName3>=<initValue3>
<varName4>=<initValue4>
export <varName1> <varName2> <varName3> <varName4>

To check if it works just log in as one of your users and get the actual variable settings (which should be the initValues above) by typing:
echo $<varname1>
echo $<varname2>
echo $<varname3>
echo $<varname4>

The file &quot;.profile&quot; is in the users home directory which is set when you create a user (look at /etc/passwd).
 
In case you didn't understand what F.Regal said, if you want a variable set for ALL users, then you must set it in the file /etc/profile. You will need root access to do this. /etc/profile is executed for ALL users at login, before any personal .profile file is executed.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top