bash - 如何将 config ini 文件转换为 bash 中的系统环境?

标签 bash

我有如下配置文件

# 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/

相关文章:

linux - 使用 for 循环 seq 分配动态 bash 变量名

linux - 使用 'ls -F'时不同指标的含义

bash - 使用脚本编辑 crontab

file - 如何将 basename 放入变量中?

linux - awk 使用动态列号

bash - 等待最后创建的进程( fork 的守护进程)结束

bash - 如何在不进入容器的情况下运行docker容器

python - 如何在Python脚本中将随机参数传递给另一个Python程序?

bash - 如何根据 awk 中的多个范围计算行数?

bash - 如何在 bash 条件语句中检查 `npm run test` 的结果