You are not logged in.

#1 2007-08-09 23:35:24

mrbug
Member
Registered: 2007-07-17
Posts: 221

single-session bash environment variables

I would like to run a program with a specific proxy, but I don't want any other programs to use that proxy. Would something like this work?

#!/bin/sh
http_proxy=proxy_address
program_name
exit 0

Do I need to export the http_proxy variable? It seems like the variable would be persistent instead of just being used for the one program that is being called.


dvdtube - download all uploads from a YouTube user and then optionally create a DVD.
(Regular version AUR link / SVN version AUR link)

Offline

#2 2007-08-09 23:59:16

big_gie
Member
Registered: 2005-01-19
Posts: 637

Re: single-session bash environment variables

export would give the variable to child processes. So you need to use it. With your script, the child process (program_name) won't see the variable.

Since export give the variable to child processes, and not parent, the variable wont be set in your running terminal.

#!/bin/sh
export http_proxy=proxy_address
program_name
exit 0

Offline

#3 2007-08-10 00:10:56

mrbug
Member
Registered: 2007-07-17
Posts: 221

Re: single-session bash environment variables

Ah.. Thanks for replying!

So then the export lines in .bashrc send the variables only to your spawned (which turns out to be every) bash processes? That must be what was confusing me...

Just out of curiosity, how would you (if it's possible) send variables to a parent process?


dvdtube - download all uploads from a YouTube user and then optionally create a DVD.
(Regular version AUR link / SVN version AUR link)

Offline

#4 2007-08-10 02:26:58

big_gie
Member
Registered: 2005-01-19
Posts: 637

Re: single-session bash environment variables

mrbug wrote:

Ah.. Thanks for replying!

So then the export lines in .bashrc send the variables only to your spawned (which turns out to be every) bash processes? That must be what was confusing me...

Exactly wink

mrbug wrote:

Just out of curiosity, how would you (if it's possible) send variables to a parent process?

I think it's not possible. Please correct me if I'm wrong!

Offline

#5 2007-08-12 04:28:34

mrbug
Member
Registered: 2007-07-17
Posts: 221

Re: single-session bash environment variables

Now that I think about it, wouldn't the ability to send variables to a parent process possibly be a huge security hole?

Again, thanks for your response.. it's cleared up a huge misconception that I have had for quite a while.


dvdtube - download all uploads from a YouTube user and then optionally create a DVD.
(Regular version AUR link / SVN version AUR link)

Offline

Board footer

Powered by FluxBB