shell输出有换行的值一般是不会换行的,要想换行怎么办呢?看下面代码

test.sh:

#!/bin/sh

list=`ls -l`

# 这样子输出只会有单行
echo '一般的输出:'
echo $list

# 多行输出
echo '换行输出:'
echo "$list" | while read i  
do
	 echo $i # 输出
done

输出:

[root@localhost shell]# ./test.sh 
一般的输出:
total 4 drwxr-xr-x 2 root root 6 Apr 6 05:45 abc.txt -rwxr-xr-x 1 root root 185 Apr 5 21:46 test.sh
换行输出:
total 4
drwxr-xr-x 2 root root 6 Apr 6 05:45 abc.txt
-rwxr-xr-x 1 root root 185 Apr 5 21:46 test.sh


你可能感兴趣的文章