How do you append to an already existing string?

后端 未结 7 530
孤城傲影
孤城傲影 2020-12-12 16:38

I want append to a string so that every time I loop over it will add say \"test\" to the string.

Like in PHP you would do:

$teststr = \"test1\\n\"
$t         


        
相关标签:
7条回答
  • 2020-12-12 17:36

    thank-you Ignacio Vazquez-Abrams

    i adapted slightly for better ease of use :)

    placed at top of script

    NEW_LINE=$'\n'
    

    then to use easily with other variables

    variable1="test1"
    variable2="test2"
    
    DESCRIPTION="$variable1$NEW_LINE$variable2$NEW_LINE"
    

    OR to append thank-you William Pursell

    DESCRIPTION="$variable1$NEW_LINE"
    DESCRIPTION+="$variable2$NEW_LINE"
    
    echo "$DESCRIPTION"
    
    0 讨论(0)
提交回复
热议问题