1
我想以与在终端上运行命令时输出的格式相同的格式来回显命令的输出,但由于某些原因,使用echo似乎消除了换行符。如何从捕获的命令中回显多行输出?
实施例:
$ 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)
此外,可以颜色被保持在所解析的输出? (使用回声,彩色不保)
颜色从未出现过。 git注意到输出不是tty,也没有打印颜色的转义码。 – 2012-02-02 16:29:01
在你的OUTPUT-line之前试试'IFS ='\ n'',看看它是否有帮助。 – bos 2012-02-02 16:35:28
参见http://unix.stackexchange.com/questions/17732/where-has-the-trailing-newline-char-gone-from-my-command-substitution – 2012-02-02 16:36:40