user90100
user90100

Reputation: 23

How to compare two tar files in bash without using temporary files?

I'm struggling to achieve folowing without temp. files.

#!/bin/bash
tar ztf "$1" | sort > tmp1
tar ztf "$2" | sort > tmp2
comm -1 -3 tmp{1,2}|while read line; do echo -e "$1: $line\n"; done
comm -2 -3 tmp{1,2}|while read line; do echo -e "$2: $line\n"; done
rm tmp{1,2}

how to do this without tmp files ?

Upvotes: 2

Views: 1053

Answers (1)

huon
huon

Reputation: 102106

Since you are using each temp file twice, the answer is almost certainly no. However, if you modify the script to use a single command (e.g. comm by itself, or diff) then the following should work:

diff <(tar ztf "$1" | sort) <(tar ztf "$2" | sort)

This uses process substitution.

(Also, just as an aside, one should use mktemp to create temporary files)

Upvotes: 4

Related Questions