How to output a multiline string in Bash?

后端 未结 9 1773
忘了有多久
忘了有多久 2021-01-29 18:14

How can I output a multipline string in Bash without using multiple echo calls like so:

echo \"usage: up [--level | -n ][--help][--version         


        
9条回答
  •  情书的邮戳
    2021-01-29 18:42

    One more thing, using printf with predefined var as template.

    msg="First line %s
    Second line %s
    Third line %s
    "
    
    one='additional message for the first line'
    two='2'
    tri='this is the last one'
    
    printf "$msg" "$one" "$two" "$tri"
    

    This ^^^ will print whole message with additional vars inserted instead of '%s' in provided order.

提交回复
热议问题