我正在编写一个 shell 脚本,它将命令的输出存储在一个变量中,处理输出,然后回显结果。这是我所拥有的:
stuff=$(diff -u pens tape)
# process the output
echo $stuff
问题是,我从运行脚本得到的输出是这样的:
--- pens 2009-09-27 10:29:06.000000000 -0400 +++ tape 2009-09-18 16:45:08.000000000 -0400 @@ -1,4 +1,2 @@ -highlighter -marker -pencil -POSIX +masking +duct
而我期待这个:
--- pens 2009-09-27 10:29:06.000000000 -0400
+++ tape 2009-09-18 16:45:08.000000000 -0400
@@ -1,4 +1,2 @@
-highlighter
-marker
-pencil
-POSIX
+masking
+duct
看起来换行符正在以某种方式被删除。我如何让他们说出来?