Monday, May 14, 2012

Include variables to a shell script from an external script

file1 include.sh

#!/bin/bash
var1="Hello there"

file2 includetest.sh

#!/bin/bash
. include.sh
echo $var1
#file2 has access to all variables defined in file1


>>>>Run file2 and you see the required output.
>>chmod +x includetest.sh
>>./includetest.sh

No comments:

Post a Comment