What do you think? I was afraid to overwrite the infile so I make the user specify an outfile. Maybe if I did better error checking it would be okay to overwrite?

The user can choose to overwrite by specifying the same file for both infile and outfile.

#!/bin/sh

[ -z "$1" -o -z "$2" ] && { echo "$0 infile outfile"; exit 1; }
[ -z "$EDITOR" ] && { echo "\$EDITOR must be defined"; exit 1; }

infile="$1"
outfile="$2"
dump="xxd -g1"
dedump="xxd -r"

tmpfile=$(mktemp)
$dump "$infile" > "$tmpfile"
$EDITOR "$tmpfile"
$dedump $tmpfile > "$outfile"
rm "$tmpfile"

Reply via email to