linux: echo 保留变量的换行符

文件test如下所示:

1. 如果echo的变量加上双引号(例如"$need1"),那么就能保留变量的换行符:

while IFS= read -r line
do
need1=`echo "$line" | awk '{print $6}' | tr "," "\n"`
echo "$need1"
done < test

效果如下:

2. 如果echo的变量不加双引号(例如$need1),那么就不能保留变量的换行符:

while IFS= read -r line
do
need1=`echo "$line" | awk '{print $6}' | tr "," "\n"`
echo $need1
done < test

效果如下:

posted @ 2022-06-29 17:17  橙子牛奶糖  阅读(993)  评论(0编辑  收藏  举报