Hi Venkat.

> 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.

> 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

Reply via email to