【问题标题】:Write multiple variables in a file to can read them later在一个文件中写入多个变量以便以后读取它们
【发布时间】:2015-06-25 01:01:28
【问题描述】:

有没有一种简单的方法可以将多个变量写入一个文件,然后再读取它们?

例如将下一个变量写入文件:

test=1
b=3
a=earth

echo "test=1" > variables.prop
echo "b=3" >> variables.prop
echo "a=earth" >> variables.prop

并以某种方式返回指定变量的值并使用它。 喜欢

*command to import the variable "test" from the text file*
echo $test

*command to import the variable "b" from the text file*
echo $b

“test”的预期输出应该是“1”,“b”应该是“3”。

【问题讨论】:

    标签: bash file variables command sh


    【解决方案1】:

    完全按照您的操作创建variables.prop,然后使用. 命令(AKA source)将其读入。

    . variables.prop
    
    echo "$test"
    echo "$b"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 2014-07-03
      • 1970-01-01
      相关资源
      最近更新 更多