diffing from a tar file
A. Pagaltzis
pagaltzis at gmx.de
Sat Apr 21 21:46:46 EDT 2007
* Kragen Javier Sitaker <kragen at pobox.com> [2007-04-21 09:40]:
> #!/bin/sh
> set -e
> usage="Usage: $0 checkpoint.tar.gz"
> : ${1?$usage}
> mkdir old
> trap 'rm -rf old' 0
> (cd old; tar xzf ../"$1")
> dir="$(ls old | head -1)"
> diff -urN old/"$dir" "$dir"
You can use mktemp(1) to make this robust. Also note that the $()
syntax for command substitution is a bash innovation, so the
/bin/sh shebang is wrong. Lastly, GNU and BSD tar have a handy -C
switch.
#!/bin/bash
set -e
usage="Usage: $0 checkpoint.tar.gz"
: ${1?$usage}
TMPDIR=`mktemp -d`
mkdir "$TMPDIR"
trap 'rm -rf "$TMPDIR"' 0
tar xzf "$1" -C "$TMPDIR"
dir="$(ls "$TMPDIR" | head -1)"
diff -urN "$TMPDIR/$dir" "$dir"
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
More information about the Kragen-discuss
mailing list