我有如下配置文件
# this is sample config file like config.ini
APP_HOME=/usr/local/bin
DATABASE_DIR=/usr/local/database
一般为了作为系统环境访问,需要在前面使用export
# this is sample config file like config.rc
export APP_HOME=/usr/local/bin
export DATABASE_DIR=/usr/local/database
我可以
$ source config.rc
$ echo "APP_HOME is $APP_HOME"
APP_HOME is /usr/local/bin
现在将配置文件 config.ini
转换为系统环境的最简单方法是哪一种?可以结合sed
/awk
命令
最佳答案
您可以告诉 shell 自动导出变量,如果您真的需要导出它。
set -a # turn on automatic export
source config.ini # execute all commands in the file
set +a # turn off automatic export
关于bash - 如何将 config ini 文件转换为 bash 中的系统环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22534737/