简体   繁体   English

如何在config.sh中将变量包含到a.sh和b.sh中?

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

I've file config.sh: 我有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 . 我想用$data_dir$bin_dir在两个独立的脚本a.shb.sh

How do I do it? 我该怎么做?

I tried this in a.sh and b.sh: 我在a.sh和b.sh中尝试过:

sh "config.sh"

But $data_dir and $bin_dir are empty. 但是$data_dir$bin_dir为空。

I also tried this: 我也试过这个:

/bin/bash "config.sh"

Thanks for help. 感谢帮助。

You need to source the file, not execute it. 您需要source文件,而不是执行它。 In a.sh and b.sh : a.shb.sh

. config.sh

or in bash , the more readable alternative 或以bash ,更具可读性

source config.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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