如何在变量中添加带有新行的命令?

如何在变量中添加带有新行的命令?

正如你所知,当我们编写list=$(ls -l)所有添加的文件时,$list如下所示:

total 0 drwx------ 7 mine-pc staff 238 Dec 22 11:32 Applications drwxr-xr-x@ 6 mine-pc staff 204 Jan 11 11:00 Applications (Parallels) drwx------+ 21 mine-pc staff 714 Jan 9 22:33 Desktop drwx------+ 33 mine-pc staff 1122 Jan 7 23:43 Documents drwx------+ 83 mine-pc staff 2822 Jan 11 00:42 Downloads drwx------@ 71 mine-pc staff 2414 Dec 22 01:10 Library drwx------+ 21 mine-pc staff 714 Jan 10 23:48 Movies drwx------+ 4 mine-pc staff 136 Sep 27 17:48 Music drwxr-xr-x 5 mine-pc staff 170 Jan 4 16:25 Parallels drwx------+ 9 mine-pc staff 306 Dec 29 13:06 Pictures drwxr-xr-x+ 5 mine-pc staff 170 Sep 27 15:41 Public

我怎样才能$list像这样插入它:

drwx------   7 mine-pc  staff   238 Dec 22 11:32 Applications
drwxr-xr-x@  6 mine-pc  staff   204 Jan 11 11:00 Applications (Parallels)
drwx------+ 21 mine-pc  staff   714 Jan  9 22:33 Desktop
drwx------+ 33 mine-pc  staff  1122 Jan  7 23:43 Documents
drwx------+ 83 mine-pc  staff  2822 Jan 11 00:42 Downloads
drwx------@ 71 mine-pc  staff  2414 Dec 22 01:10 Library
drwx------+ 21 mine-pc  staff   714 Jan 10 23:48 Movies
drwx------+  4 mine-pc  staff   136 Sep 27 17:48 Music
drwxr-xr-x   5 mine-pc  staff   170 Jan  4 16:25 Parallels
drwx------+  9 mine-pc  staff   306 Dec 29 13:06 Pictures
drwxr-xr-x+  5 mine-pc  staff   170 Sep 27 15:41 Public

答案1

$list已经是这种格式了。使用引号:

echo "$list"

相关内容