임시 파일이없는 두 프로그램의 Diff 출력
내가 너무 프로그램이 말 a
과 b
내가 함께 실행할 수 ./a
및 ./b
.
임시 파일에 먼저 쓰지 않고 출력을 비교할 수 있습니까?
<(command)
파일 이름 인 것처럼 하나의 명령 출력을 다른 프로그램에 전달하는 데 사용 합니다. Bash는 프로그램의 출력을 파이프로 파이프하고 /dev/fd/63
외부 명령 과 같은 파일 이름을 전달합니다 .
diff <(./a) <(./b)
마찬가지로 당신이 사용할 수있는 >(command)
당신이 파이프 뭔가 원하는 경우 에 명령.
이것을 Bash 매뉴얼 페이지에서 "프로세스 대체"라고합니다.
나란히 비교하고 싶다면 두 대답에 모두 추가하십시오 vimdiff
.
vimdiff <(./a) <(./b)
이 같은:
한 가지 옵션은 명명 된 파이프 (FIFO) 를 사용하는 것입니다 .
mkfifo a_fifo b_fifo
./a > a_fifo &
./b > b_fifo &
diff a_fifo b_fifo
... but John Kugelman's solution is much cleaner.
For anyone curious, this is how you perform process substitution in using the Fish shell:
Bash:
diff <(./a) <(./b)
Fish:
diff (./a | psub) (./b | psub)
Unfortunately the implementation in fish is currently deficient; fish will either hang or use a temporary file on disk. You also cannot use psub for output from your command.
Adding a little more to the already good answers (helped me!):
The command docker
outputs its help to STD_ERR
(i.e. file descriptor 2)
I wanted to see if docker attach
and docker attach --help
gave the same output
$ docker attach
$ docker attach --help
Having just typed those two commands, I did the following:
$ diff <(!-2 2>&1) <(!! 2>&1)
!! is the same as !-1 which means run the command 1 before this one - the last command
!-2 means run the command two before this one
2>&1 means send file_descriptor 2 output (STD_ERR) to the same place as file_descriptor 1 output (STD_OUT)
Hope this has been of some use.
For zsh, using =(command)
automatically creates a temporary file and replaces =(command)
with the path of the file itself. With normal Process Substitution, $(command)
is replaced with the output of the command.
This zsh feature is very useful and can be used like so to compare the output of two commands using a diff tool, for example Beyond Compare:
bcomp =(ulimit -Sa | sort) =(ulimit -Ha | sort)
For Beyond Compare, note that you must use bcomp
for the above (instead of bcompare
) since bcomp
launches the comparison and waits for it to complete. If you use bcompare
, that launches comparison and immediately exits due to which the temporary files created to store the output of the commands disappear.
Read more here: http://zsh.sourceforge.net/Intro/intro_7.html
Also notice this:
Note that the shell creates a temporary file, and deletes it when the command is finished.
and the following which is the difference between $(...)
and =(...)
:
If you read zsh's man page, you may notice that <(...) is another form of process substitution which is similar to =(...). There is an important difference between the two. In the <(...) case, the shell creates a named pipe (FIFO) instead of a file. This is better, since it does not fill up the file system; but it does not work in all cases. In fact, if we had replaced =(...) with <(...) in the examples above, all of them would have stopped working except for fgrep -f <(...). You can not edit a pipe, or open it as a mail folder; fgrep, however, has no problem with reading a list of words from a pipe. You may wonder why diff <(foo) bar doesn't work, since foo | diff - bar works; this is because diff creates a temporary file if it notices that one of its arguments is -, and then copies its standard input to the temporary file.
참고 URL : https://stackoverflow.com/questions/3800202/diff-output-from-two-programs-without-temporary-files
'Programming' 카테고리의 다른 글
Heroku / GoDaddy : 나체 도메인을 www로 보내기 (0) | 2020.06.18 |
---|---|
MySQL에서 ENUM 타입 칼럼에 멤버를 더 추가하려면 어떻게합니까? (0) | 2020.06.18 |
HttpClient에 Http 헤더 추가 (0) | 2020.06.16 |
메모리 힙이란 무엇입니까? (0) | 2020.06.16 |
뷰포트 확대 / 축소 사용 중지 iOS 10 이상 사파리? (0) | 2020.06.16 |