本文翻译自: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