shell在变量中存储多行输出

其实直接

res=$(echo -e "abc\ndef")

即可。但是输出时不能直接

echo $res

这样只会输出

abc def

正确做法是

echo "$res"
abc
def

原文:https://stackoverflow.com/questions/613572/capturing-multiple-line-output-into-a-bash-variable/613580

posted @ 2024-09-28 14:11  寻找繁星  阅读(42)  评论(0)    收藏  举报