LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   reading variables from other file (https://www.linuxquestions.org/questions/programming-9/reading-variables-from-other-file-631209/)

RudraB 03-28-2008 05:37 AM

reading variables from other file
 
i have two shell script.
the nrec is declared once in first script as:
echo -e "Number of Recursion step\nThe default value is 30"
read nrec

And the second one is
#!/bin/bash
#This script manages the Results mostly by
#creating seperate files for each orbital
#from the main o/p ab.dat
for ((i=1; i<=9; i++))
do
cnt=`expr $i \* $nrec`
#echo "$cnt"
head -$cnt RESULT/ab.dat|tail -$nrec>RESULT/$i.dat
done


is there any way to pass the variable nrec of first script to the 2nd one without reading it once again??

colucix 03-28-2008 06:06 AM

If the second script is launched from the first, you can use export to make the variable available to all the processes launched from the first script, e.g.
Code:

#!/bin/bash
echo -e "Number of Recursion step\nThe default value is 30"
read nrec

export nrec=$nrec
/path/to/second_script.sh

in this case the second script inherits the variable nrec from the environment.

Instead, if the two scripts are launched separately, I think the only way is that the first script writes the value of nrec somewhere in a file and the second script waits for the file creation and then read the value of nrec (and eventually deletes the file).


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