Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have two shell script files test1.sh and test2.sh . I have another file called translogs.txt.
Now I need to copy the values of two variables in test1.sh to translog.txt and the same variables need to be copied to the corresponding values in test2.sh.

test1.sh

#!/bin/sh
ONE="000012"
TIME="2013-02-19 15:31:06"
echo -e "$ONE\n$TIME">translog.txt;

translog.txt

ONE="000012"
TIME="2013-02-19 15:31:06"

But here in test2.sh, I want the same value as in translog.txt to the corresponding variable like ONE and TIME should have the same value as in translog.txt

test2.sh

#!/bin/sh
ONE="000012"
TIME="2013-02-19 15:31:06"
share|improve this question
    
Are those the only contents of translog.txt? –  Dennis Feb 19 '13 at 12:27
    
@Dennis Yes they are the only contents –  Rudra Feb 19 '13 at 12:31
add comment

1 Answer 1

If you want the contents of translog.txt to actually look like in your example and you don't mind switching from dash to bash, you can use source (see Shell Builtin Commands in man bash) to simply execute the contents of translog.txt in the current shell.

test1.sh:

#!/bin/bash
ONE="000012"
TIME="2013-02-19 15:31:06"
echo -e "ONE=\"$ONE\"\nTIME=\"$TIME\"">translog.txt;

test2.sh

#!/bin/bash
source translog.txt
echo "ONE:  $ONE"
echo "TIME: $TIME"

Test

$ ./test1.sh
$ cat translog.txt 
ONE="000012"
TIME="2013-02-19 15:31:06"
$ ./test2.sh
ONE:  000012
TIME: 2013-02-19 15:31:06
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.