gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 09:34:46 25 4
gpt4 key购买 nike

我有如下配置文件

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com