IMPORT VARIABLE(S) AND FUNCTION(S) FROM FILE

September 14th, 2006 durian Posted in Common, source | Hits: 20738 | 4 Comments »

If you have a lot of variables set in a configuration file and you need to access all those variables quickly, you can try to use

source filename

For example, you have a configuration file named /etc/vars.conf with the following content:

VAR1=hkong

VAR2=is

VAR3=leaving

function test1 {

echo $VAR3 $VAR2 $VAR1

}

You can then invoke

source /etc/vars.conf

Then the variables and function will be accessible as depicted in the following example

echo $VAR1 $VAR2 $VAR3

hkong is leaving

test1

leaving is hkong

This command is most commonly used by startup scripts to import variables

and functions

4 Responses to “IMPORT VARIABLE(S) AND FUNCTION(S) FROM FILE”

  1. (: Ya I am leaving soon.

  2. Good Job.3 months ago, it is still an idea, but just 3 months, u have realize your dream..继续努力!

  3. Advantageously, this submit is definitely the greatest on this invaluable topic. I fit in along with your explanations and can eagerly look forward to your forthcoming updates. Simply saying thanks won’t just be enough, for the great readability in your documentation. I will instantly grab your rss feed to remain abreast of any updates. Fabulous work and a variety of success in what you are promoting dealings!

  4. Thanks for posting this. It saved me hours of searching!

Leave a Reply