-->

DEVOPSZONES

  • Recent blogs

    How to write multiple line string using Bash with variables?

     Solution:

    For one record in config file: 
    #!/bin/bash
    var1="abc"
    var2="xyz"
    cat >/etc/config.conf <<EOL
    line 1, ${var1}
    line 2,
    line 3, ${var2}
    line 4 line
    ...
    EOL

    cat /etc/config.conf


    For multiple record in config file:
    #!/bin/bash
    var1="abc"
    var2="xyz"
    for i in `cat sometext.txt`
    do
    cat >>/etc/config.conf <<EOL
    line 1, ${var1}
    line 2,
    line 3, ${var2}
    line 4 line
    ...
    EOL
    done

    No comments