How to split strings over multiple lines in Bash?

前端 未结 11 1183
[愿得一人]
[愿得一人] 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:40

    You can use bash arrays

    $ str_array=("continuation"
                 "lines")
    

    then

    $ echo "${str_array[*]}"
    continuation lines
    

    there is an extra space, because (after bash manual):

    If the word is double-quoted, ${name[*]} expands to a single word with the value of each array member separated by the first character of the IFS variable

    So set IFS='' to get rid of extra space

    $ IFS=''
    $ echo "${str_array[*]}"
    continuationlines
    

提交回复
热议问题