开发者

How to store and echo multiple lines elegantly in bash? [duplicate]

This question already has answers here: Capturing multiple line output into a Bash variable (7 answers) 开发者_开发技巧 Closed 5 years ago.

I'm trying to capture a block of text into a variable, with newlines maintained, then echo it.

However, the newlines don't seemed to be maintained when I am either capturing the text or displaying it.

Any ideas regarding how I can accomplish this?

Example:

#!/bin/bash

read -d '' my_var <<"BLOCK"
this
is
a
test
BLOCK

echo $my_var

Output:

this is a test

Desired output:

this

is

a

test


echo "$my_var"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜