简体   繁体   中英

How do I include variables in `config.sh` into `a.sh` and `b.sh`?

I've file config.sh:

data_dir=/home/olle/investing_data
bin_dir=/home/olle/investing_bin

I want to use $data_dir and $bin_dir in two separate scripts a.sh and b.sh .

How do I do it?

I tried this in a.sh and b.sh:

sh "config.sh"

But $data_dir and $bin_dir are empty.

I also tried this:

/bin/bash "config.sh"

Thanks for help.

You need to source the file, not execute it. In a.sh and b.sh :

. config.sh

or in bash , the more readable alternative

source config.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM