LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using a variable in another variable. (https://www.linuxquestions.org/questions/programming-9/using-a-variable-in-another-variable-655546/)

dina3e 07-13-2008 09:18 PM

using a variable in another variable.
 
my problem is, i have to use some of the variable from one shell script to other shell script.Where the varible is already defined in first script and we just simple use the defined variable in the second script. (like c static and extern variable storage classes)

Mr. C. 07-13-2008 11:03 PM

To pass a variable to another script depends on how you invoke or use the other script:

*) if you source (.) a file, all variables are available, as this just reads to contents into the current shell process
*) if you call the second script by way of execution, you must pass variables either via exported environment variables or by command line arguments.

dina3e 07-17-2008 10:51 PM

Quote:

Originally Posted by Mr. C. (Post 3213526)
To pass a variable to another script depends on how you invoke or use the other script:

*) if you source (.) a file, all variables are available, as this just reads to contents into the current shell process
*) if you call the second script by way of execution, you must pass variables either via exported environment variables or by command line arguments.

i have define some of the variable in one file and later i use these variables. and these variable act as static data type.so how i do link all these and access these data type.

Mr. C. 07-17-2008 11:17 PM

Code:

$ cat file1

var1=10

$ cat file2
echo Before: $var1
. ./file1
echo After: $var1

$ sh ./file2
Before:
After: 10



All times are GMT -5. The time now is 08:07 PM.