入力ファイルと出力ファイル (test.in と test.out) があり、標準入力が test.in から来るようにリダイレクトされたプログラム "./myprogram" があり、標準出力からキャプチャされた結果を使用して比較するとします。 test.out で
どのように正確に比較できますか
考えている、
if [ $(myprogram < test.in) == $(cat test.out) ]
助言がありますか?
cmp
†を使用-
して、比較するファイルの 1 つとして指定します。これにより、stdin を使用するように指示されます。
if myprogram < test.in | cmp -s - test.out; then
一時ファイルを作成せずに 2 つのコマンドの出力を比較する場合は、この機能を使用し<(cmd)
ます。( で「プロセス置換」を検索してman bash
ください。)
if cmp -s <(myprogram < test1.in) <(myprogram < test2.in); then
†またはdiff
、違いを知りたい場合。
私は差分を使用します。このようなもの:
if cat test.in | myprogram | diff - test.out