Source environment variable in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Source environment variable in script
# 1  
Old 07-19-2011
Source environment variable in script

Hi,

I construct a bash script to finish some tasks. One of the task is to set up some environment variables. There is already one script file to complete the environment variables setting work. I am not able to know the detail of how to set these variables. So, I may just need to call this script in my script file.

Assume that my script file is myscript.sh, and another script file is setvar.sh. I start a terminator and run my script. So, the process tree will be like this:
init-login-bash-myscript.sh-setvar.sh
Here is the difficulty: I want these variables to be available in my working shell. But it seems that when I run my script, a child shell will be created, and these variables (set in the setvar.sh) are only available for this child shell.

So, what can I do in my script to let these variables become available for the whole working shell, other than the child shell that is created to run my script.
# 2  
Old 07-19-2011
Source the setvar.sh script in myscript.sh:
Code:
. ./setvar.sh

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 07-19-2011
Thanks, Franklin.

After doing this, the environment variables are only available for the child shell (created to run myscript.sh), but the environment variables are not available for parent shell. After myscript.sh exits, all these environment variables will die.
# 4  
Old 07-19-2011
Can't you source the setvar script before you start the scripts e.g. in your .profile?
This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 07-19-2011
Yes,I cannot access to files such as .profile or .bashrc, etc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to change Linux Terminal environment variable in a perl or bash script?

Hi, I meet an problem that it cannot change Terminal environment variable in a perl or bash script. This change can only exist and become effective in script lifetime. But I want to make this change take effect in current opened Terminal. In our view, the thought seems to be impossible, As... (9 Replies)
Discussion started by: weichanghe2000
9 Replies

2. UNIX for Dummies Questions & Answers

Overwrite a Source Script Variable Value

Hello All, How do i overwrite a sourced script variable value. Sourced Script: GEN_PARAM_LIST4=""$LOG_DIR"/dwh_GenerateXMLFile.lst" GEN_PARAM_LIST4_v2=""$LOG_DIR"/dwh_GenerateXMLFile.v2.lst" I am using below statement for replacing. Script2: &&... (1 Reply)
Discussion started by: Ariean
1 Replies

3. UNIX for Dummies Questions & Answers

environment variables for compiling from source

Hello, I was trying to istall Gdkpixbuff 2.26.1 in my laptop ubuntu 11.10, when I did: ./configure and I got these error message *** 'pkg-config --modversion glib-2.0' returned 2.33.1, but GLIB (2.30.0) was found! If pkg-config was correct, then it is best *** to remove the old version of GLib.... (1 Reply)
Discussion started by: yifangt
1 Replies

4. Shell Programming and Scripting

environment variable in shell script called through crontab

Please help me on below.. https://www.unix.com/shell-programming-scripting/141533-retrieve-value-environment-variable-shell-script-called-crontab.html#post302442024 I'm still here. I can still see you! (0 Replies)
Discussion started by: jadoo_c2
0 Replies

5. Shell Programming and Scripting

Retrieve the value of environment variable in shell script which called from crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (0 Replies)
Discussion started by: jadoo_c2
0 Replies

6. Shell Programming and Scripting

Setting environment variable using shell script

Hi All, I'm trying to write an menu driven program to automate some functions which involve loging to multiple hosts. The hosts can differ for every use, so I thought I would use an config file to get the hostnames. Now I need to set those values in the config file to environment variable to... (6 Replies)
Discussion started by: arun_maffy
6 Replies

7. Shell Programming and Scripting

reading environment variable from awk script

Hi All, I am using SunSolaris machine. I need to get the value of environment variable from awk begin. Then use that value as the start number of a sequence and use that in my print statement. But it is not reading the value from environment variable. I have tried the following: ... (5 Replies)
Discussion started by: prashas_d
5 Replies

8. Shell Programming and Scripting

Simple script to return environment variable

HI , In the below script I am trying to return the value of the environment variable TIBCO_HOME to the caller #! /usr/bin/csh set VAR_NAME=$1 echo VAR_NAME On the aix console.. set to setenv TIBCO_HOME /app/tibco When I execute the script... myscript.sh TIBCO_HOME, the script... (5 Replies)
Discussion started by: bce_groups
5 Replies

9. Shell Programming and Scripting

Setting environment variable on a remote solaris machine using shell script

Hi, I am trying to set environment variable on a remote machine. I want to do it by running a shell script Here's what I am doin rsh <remote-hostname> -l root "cd /opt/newclient; . ./setp.sh" In setp.sh, I have ############################# cd ../newlib; export... (1 Reply)
Discussion started by: eamani_sun
1 Replies

10. Shell Programming and Scripting

problem in getting the path of environment variable set in bashrc in my shell script

hi all i have joined new to the group. i have set an variable in my bashrc file. .bashrc PROGHOME=/home/braf/braf/prog export PROGHOME but while using it in my shell script its path is not taken and i had to explicitly give the export command to set the path. in my script... (8 Replies)
Discussion started by: krithika
8 Replies
Login or Register to Ask a Question