How to set environment variables?

HSN


Joined
Nov 27, 2006
Messages
27
Reaction score
0
Points
1
Hi,

How can I set environment variables in MAC OS X Leopard? I want to use some UNIX environment variables from the command line. I tried to use 'setenv' but it's not there!

Any other ways?
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
setenv was for tcsh. Your probably using bash in Leopard. You need to use the export command in your .bashrc or .profile files.

PATH=$PATH:/usr/local/bin
export PATH

You can type them in directly, but they will only last for that one terminal session.
 
OP
H

HSN


Joined
Nov 27, 2006
Messages
27
Reaction score
0
Points
1
That helps thank you.
But, what if I want to add a new variable?
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
Do one of the following for each of the new variables:

export variable=variable_string

variable=variable_string
export variable

You will need to update your .bashrc file to make your changes permanent.
 
OP
H

HSN


Joined
Nov 27, 2006
Messages
27
Reaction score
0
Points
1
I don't see any .bashrc in my home. Where should this be located in Leopard?
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
It's not there by default, you have to make one. You can copy the bashrc from /etc or make one from scratch. If you do the copy from /etc, be sure to put a period in front of the name to make it invisible.

And for more info, the relevant part of the bash man page:
export -p
The supplied names are marked for automatic export to the envi-
ronment of subsequently executed commands. If the -f option is
given, the names refer to functions. If no names are given, or
if the -p option is supplied, a list of all names that are
exported in this shell is printed. The -n option causes the
export property to be removed from each name. If a variable
name is followed by =word, the value of the variable is set to
word. export returns an exit status of 0 unless an invalid
option is encountered, one of the names is not a valid shell
variable name, or -f is supplied with a name that is not a func-
tion.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top