How to split strings over multiple lines in Bash?

前端 未结 11 1148
[愿得一人]
[愿得一人] 2020-11-29 16:35

How can i split my long string constant over multiple lines?

I realize that you can do this:

echo "continuation \\
lines"
>continuation li         


        
11条回答
  •  自闭症患者
    2020-11-29 17:25

    Depending on what sort of risks you will accept and how well you know and trust the data, you can use simplistic variable interpolation.

    $: x="
        this
        is
           variably indented
        stuff
       "
    $: echo "$x" # preserves the newlines and spacing
    
        this
        is
           variably indented
        stuff
    
    $: echo $x # no quotes, stacks it "neatly" with minimal spacing
    this is variably indented stuff
    

提交回复
热议问题