2012-02-02 1 views
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) 

또한 색 파싱 출력 유지 될 수 있는가? 큰 따옴표를 사용하면 줄 바꿈이 유지됩니다

+1

색상이 없었습니다. git은 출력이 tty가 아니며 색상의 이스케이프 코드를 출력하지 않는다는 것을 알게되었습니다. –

+0

OUTPUT 줄 앞에'IFS = '\ n''을 시도해보고 도움이되는지 확인하십시오. – bos

+0

참조 http://unix.stackexchange.com/questions/17732/where-has-the-trailing-newline-char-gone-from-my-command-substitution –

답변

10

(사용 에코, 색은 유지되지 않았습니다) :

 
echo "$OUTPUT" 

색상에 따라 : 출력이 청각 장애없는 경우 자식이 아닌 출력 색상 코드를 않습니다 . 색상 코드를 강제로 적용하려면 다음을 수행하십시오.

 
OUTPUT=$(GIT_PAGER_IN_USE=true git status) 
관련 문제