LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   variable one script to another (https://www.linuxquestions.org/questions/programming-9/variable-one-script-to-another-385620/)

rharris72 11-22-2005 05:39 PM

variable one script to another
 
can a variable from one file be used in another so for instance

if say test.sh had

var="hello"

could i call that var form say test.1.sh

so it would display the var when i run test1.sh

basically i am writing a http interface with user input outputing that to a file and would like to use another file to exec all the variables

thanks in advance

Tinkster 11-22-2005 06:55 PM

Only if you source the script(s), and the variables are
exported ...


Cheers,
Tink

paulsm4 11-23-2005 01:17 AM

Tinkster is correct. Another alternative is to use the "." to read an initialization file.

EXAMPLE:
vi myenv =>
Code:

export ONE=1
export TWO=2
export THREE=tres

vi myscript =>
Code:

echo "BEFORE: ONE= $ONE, TWO= $TWO, THREE= $THREE."
. ./myenv
echo "AFTER: ONE= $ONE, TWO= $TWO, THREE= $THREE."

./myscript =>
Quote:

BEFORE: ONE= , TWO= , THREE= .
AFTER: ONE= 1, TWO= 2, THREE= tres.
'Hope that helps .. PSM


All times are GMT -5. The time now is 08:33 AM.