【问题标题】:Bash: append multilines string with Brackets to fileBash:将带括号的多行字符串附加到文件中
【发布时间】:2017-12-14 10:21:25
【问题描述】:

我想在文件中添加多行字符串。

我尝试使用 sed,但我不知道如何管理括号。

A='[program:process-0-10]
command=/usr/local/bin/process --config /home/10min/config.yaml --verbose
process_name=process-0-10
autorestart=true
startsecs=15
stopsignal=INT
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/0-10_stderr.log
stdout_logfile=/var/log/0-10_stderr.log
stderr_logfile_maxbytes=5MB"'

sed ${A} /etc/conf/supervisord.conf

【问题讨论】:

  • 你想在哪里添加它?如果您只想追加到该文件,请使用echo "${A}" >> /etc/conf/supervisord.conf

标签: bash sed concatenation sh


【解决方案1】:

感谢您的回答。

cat >>/etc/p/supervisord.conf <<EOF

blabla

EOF

【讨论】:

    【解决方案2】:

    使用重定向:

    ~$ A='....long string....'
    ~$ echo "$A"  >> file_to_append
    ~$ printf "%s\n" "$A" >> file_to_append
    ~$ while read -r line; do echo "$line" >> file_to_append; done <<< "$A"
    

    检查我们有什么:

    ~$ cat file_to_append
    ...long string...
    ...long string...
    ...long string...
    

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 2018-06-18
      • 2023-01-07
      • 2018-10-18
      • 2018-09-13
      • 2014-11-18
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多