Print a variable with multi-line value in shell?

梦想与她 提交于 2020-06-22 08:32:05

问题


In Bash (or other shells) how can I print an environment variable which has a multi-line value?

text='line1
line2'

I know a simple usual echo $text won't work out of the box. Would some $IFS tweak help?

My current workaround is something like ruby -e 'print ENV["text"]'. Can this be done in pure shell? I was wondering if env command would take an unresolved var name but it does not seem to.


回答1:


Same solution as always.

echo "$text"



回答2:


export TEST="A\nB\nC"
echo $TEST

gives output:

A\nB\nC

but:

echo -e $TEST
A
B
C

So, the answer seems to be the '-e' parameter to echo, assuming that I understand your question correctly.



来源:https://stackoverflow.com/questions/12468233/print-a-variable-with-multi-line-value-in-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!