|
|
|
#1
|
|||
|
|||
|
Unix/Linux environment variables for simpletons
I am new to the Unix/Linux world and could do with some help regarding environment variables, shell scripts and the like. As I understand it if I have the following in a shell script:
Code:
MYVAR=somevalue export MYVAR . Is there a simple way to achieve what I was trying to do.
|
| Advertisements | |
|
|
|
|
#2
|
|||
|
|||
|
What you want to do is source the script that sets the variables:
/etc/variables.conf: Code:
MY_VAR=value Code:
#!/bin/sh . /etc/variables.conf echo $MY_VAR Run my_script.sh, and it will print "value". |
|
#3
|
|||
|
|||
|
Simple
, Cool , Thanks
|
|
#4
|
|||
|
|||
|
Also, be aware that various shells have different commands. For instance, export isn't universal; in csh, you would use setenv.
In addition, I'm pretty sure that not all shells recognize "." as equivalent to "source". |
|
#5
|
|||
|
|||
|
To elaborate...
If you have a script that you'd like to run in a new subshell (so that when it ends, your current environment is unchanged) you do what you did in the OP. If you want to run the lines of the script in your current shell, thereby modifying its environment, you have to "source" the script, like so: contents of blah.sh: Code:
export MYVAR="foobar" export MYOTHERVAR=65 Code:
myprompt> source blah.sh The tcsh equivalent of the above script would be: Code:
setenv MYVAR "foobar" setenv MYOTHERVAR 65 |
|
#6
|
|||
|
|||
|
Quote:
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|