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

set env vars within a shell

Status
Not open for further replies.

Chacalinc

Vendor
Sep 2, 2003
2,043
0
0
US
Hi,

if you run a shell like this:

Code:
# setting vars

export IP-PC1=192.10.10.10
export IP-PC1=192.10.10.20
#end

and then you run it (i.e. # ./setvars.sh) the variables exist only inside the shell, but when the shell is finished, vars are out of scope and they are lost...

Is there any way to set environments var from a shell? and then, whit another shell you can unset them?

thanks in advance.

 
sorry, in the example shell, second var should be:

Code:
IP-PC2=192.10.10.20

they are only for example... U know what I mean ;o)
 
You have to "source" the script into your current shell, not run it.

I.e.

# ./setvars.sh
won't work

# . ./setvars.sh
will work

Another way is to make sure there is no #!/bin/sh on the first line of the script as this also invokes a sub-shell rather than running it in the current shell.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top