Skip to contentSkip to conversation

newbie

DISCUSSION Venkat Raghu 4 participants 5 messages Aug 19, 2002 – Aug 20, 2002

lore
Share & tools
lore
#0 lore raw

Hi,

I have a bash script which modifies some environment variables and does some other housekeeping things. But problem is that when script finishes running, new values of environment variables are no longer visible in parent shell. So what should I do so that these new values are visible in parent. I don't want to run as ". file.sh". I have to run it as "file.sh" only.

Kindly mail me at [email protected]

Regards
Venkat.

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

#1 lore raw

Hi Venkat.

Quoted 5 lines

I have a bash script which modifies some environment variables and does some other housekeeping things. But problem is that when script finishes running, new values of environment variables are no longer visible in parent shell. So what should I do so that these new values are visible in parent.

Run your script using ". file.sh" or "source file.sh" to do that.

Quoted 2 lines

I don't want to run as ". file.sh".
I have to run it as "file.sh" only.

Unfortunately, if you run it as "file.sh" only, you start up a new shell and lose the ability to change the settings in the parent shell. This is a deliberate part of bash's design, and is to isolate the new shell from the existing one so the new shell can make changes to important environment variables to accomplish its task without causing problems for later commands.

Another option would be for your script to drop the relevant commands into the keyboard buffer for the parent shell to execute when the new shell exits. Whilst that might be an interesting exercise, it's also a pointless one when the needed functionality is already present.

If your script is one that you want executed every time you log in, then include the relevant source command in ~/.bashrc and it will be loaded at login time without problem.

Best wishes from Riley.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#3 lore raw

Hi Steven.

Quoted 4 lines
Quoted 2 lines

Another option would be for your script to drop
the relevant commands into the keyboard buffer

How is this done?

All I know is that there are programs that do just that. I wish I knew how they did it, but I don't 8-((

Best wishes from Riley.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#4 lore raw
In reply to Venkat Raghu
Quoted 10 lines · Venkat Raghu

Hi,

I have a bash script which modifies some environment variables and does some other housekeeping things. But problem is that when script finishes running, new values of environment variables are no longer visible in parent shell. So what should I do so that these new values are visible in parent. I don't want to run as ". file.sh". I have to run it as "file.sh" only.

The things you do in child process environments are inheritable only to their childs, never to parent. If they were, there would be massive security problems, just to mention one consequence...

If you want your current shell to get the new values, you have to do: . file.sh

Quoted 4 lines

Kindly mail me at [email protected]

Regards
Venkat.