【问题标题】:reading and modying the value of the .properties file by shell script in unix在 unix 中通过 shell 脚本读取和修改 .properties 文件的值
【发布时间】:2015-08-27 09:52:09
【问题描述】:

嗨,我正在更新值,直到键很简单... 但是当我遇到像 user.name 这样的键时问题就来了

以下是属性文件:-

user.name=sandeep
class=a1

以下是脚本:-

. /pro.properties


b=$(echo $user.name)

sed -i "s|$b|rohit|g" ./pro.properties

cat pro.properties

我只想将它的值从 sandeep 更改为 rohit

我也尝试过以下方法:-

  1. echo $user.name
  2. echo ${user.name}
  3. echo $(user.name)
  4. echo $'user.name'
  5. 回显 $user.name
  6. echo $"user.name"
  7. a='用户名' b=$(回声 $a)

但它没有得到那个键的值

【问题讨论】:

    标签: unix scripting properties-file


    【解决方案1】:

    Bash 不允许带有“.”的变量。在名字的中间。

    bash-3.2$ user.name=sandeep bash: user.name=sandeep: 找不到命令

    您可以使用以下命令更改行。

    sed "s|user.name=sandeep|user.name=rohit|g" <.>./pro.new

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2020-07-13
      相关资源
      最近更新 更多