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