Help us understand the problem. What is going on with this article?

標準入力同士の diff

More than 5 years have passed since last update.

ブログネタなんですが、こちらで公開した方が大勢の目に触れると思うので…

コマンド command1 の出力結果と コマンド command2 の出力結果を diff (1) で比較したい場合、bash (1) の場合は以下の様にする事で簡単に比較できる。

$ diff <(command1) <(command2)

bash 以外の posix shell の場合は以下の方式で同様の処理となる。

$ command1 | ( command2 | diff /dev/fd/3 -) 3<&0

command1 の結果は 3<&0 の記述に従って ファイルディスクリプタ 3 へ出力される。
diff の第1引数は /dev/fd/3 が指定されているので command1 の出力を受け取ることができ、
command2 の結果は直接標準出力を経由して diff の 第2引数へと渡されるので
結果として command1 の出力と command2 の出力が比較できる。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away