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
效果如下:
本文来自博客园,作者:橙子牛奶糖(陈文燕),转载请注明原文链接:https://www.cnblogs.com/chenwenyan/p/16424236.html