使用Shell脚本在文件中添加行数组

问题描述 投票:0回答:1

我正在尝试在文件中添加多行。为此,我使用了线阵并将其附加到文件中。我的shell脚本如下所示-

 Instance_Home='/home/ritu/Downloads/OHS_LINUX_SCDs'
 Http_ConfFile=$Instance_Home/httpd.conf

 array[0] = "LimitRequestBody 512000"
 array[1] = "LimitRequestFields 40"
 array[2] = "LimitRequestFieldsize 100"
 array[3] = "LimitRequestline 500"
 echo ${array[*]}  >> $Instance_Home/httpd.conf

预期结果将是:

  ># cat /home/ritu/Downloads/OHS_LINUX_SCDs/httpd.conf

   LimitRequestBody 512000
   LimitRequestFields 40
   LimitRequestFieldsize 100
   LimitRequestline 500

但是它的抛出错误类似-

 Apply-OHS-L-2.7.sh: 13: Apply-OHS-L-2.7.sh: array[0]: not found
 Apply-OHS-L-2.7.sh: 14: Apply-OHS-L-2.7.sh: array[1]: not found
 Apply-OHS-L-2.7.sh: 15: Apply-OHS-L-2.7.sh: array[2]: not found
 Apply-OHS-L-2.7.sh: 16: Apply-OHS-L-2.7.sh: array[3]: not found
 Apply-OHS-L-2.7.sh: 18: Apply-OHS-L-2.7.sh: Bad substitution

找不到此脚本出了什么问题。

arrays file append multiple
1个回答
0
投票

${array[@]}代替${array[*]}将解决问题。

您的评论发现其他内容之后。删除“ =”符号前后的空格。因此是array[0]="123"而不是array[0] = "123"

© www.soinside.com 2019 - 2024. All rights reserved.