【发布时间】:2012-02-02 16:26:28
【问题描述】:
我想以与我在终端上运行命令时输出的格式相同的格式回显命令的输出,但出于某种原因,使用回显似乎可以消除换行符。
例子:
$ OUTPUT=$(git status)
$ echo $OUTPUT
# On branch feature_install # Untracked files: # (use "git add <file>..." to include in what will be committed) # # install/ nothing added to commit but untracked files present (use "git add" to track)
但这应该已经打印出来了:
$ git status
# On branch feature_install
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# install/
nothing added to commit but untracked files present (use "git add" to track)
另外,可以在解析的输出中保持颜色吗? (使用echo,颜色不保持)
【问题讨论】:
-
颜色从来没有出现过。 git 注意到输出不是 tty 并且没有打印颜色的转义码。
-
在您的 OUTPUT 行之前尝试
IFS='\n'看看是否有帮助。