Thursday, 21 April 2022

Trying to embed newline when concat two string variables in Bash

 

  1. Inserting \n

     p="${var1}\n${var2}"
     echo -e "${p}"
    
  2. Inserting a new line in the source code

     p="${var1}
     ${var2}"
     echo "${p}"
    
  3. Using $'\n' (only Bash and Z shell)

     p="${var1}"$'\n'"${var2}"
     echo "${p}"


from: https://stackoverflow.com/questions/9139401/trying-to-embed-newline-in-a-variable-in-bash

No comments:

Post a Comment

How to check if a file contains a specific string using Bash

 In case if you want to check whether file does not contain a specific string, you can do it as follows. if ! grep -q SomeString "$File...