从键/值对文件中设置环境变量

TL;DR: How do I export a set of key/value pairs from a text file into the shell environment? TL; DR
摘要由CSDN通过智能技术生成

本文翻译自:Set environment variables from file of key/value pairs

TL;DR: How do I export a set of key/value pairs from a text file into the shell environment? TL; DR:如何将一组键/值对从文本文件导出到Shell环境中?


For the record, below is the original version of the question, with examples. 作为记录,下面是问题的原始版本,并带有示例。

I'm writing a script in bash which parses files with 3 variables in a certain folder, this is one of them: 我正在bash中编写一个脚本,该脚本分析某个文件夹中具有3个变量的文件,这是其中之一:

MINIENTREGA_FECHALIMITE="2011-03-31"
MINIENTREGA_FICHEROS="informe.txt programa.c"
MINIENTREGA_DESTINO="./destino/entrega-prac1"

This file is stored in ./conf/prac1 该文件存储在./conf/prac1中

My script minientrega.sh then parses the file using this code: 然后,我的脚本minientrega.sh使用以下代码解析文件:

cat ./conf/$1 | while read line; do
    export $line
done

But when I execute minientrega.sh prac1 in the command line it doesn't set the environment variables 但是,当我在命令行中执行minientrega.sh prac1 ,它没有设置环境变量

I also tried using source ./conf/$1 but the same problem still appl

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值