#!/bin/sh # # filter-proxy - enable filters to work on real files (using tmpfiles) # # Copyright © 2008 martin f. krafft # Released under the terms of the Artistic Licence 2.0 # set -eu cmd= file= while [ -n "${1:-}" ]; do if [ -z "${2:-}" ]; then file="$1" else case "$1" in *' '*) cmd="$cmd '$1'";; *) cmd="$cmd $1";; esac fi shift done TMPFILE="$(mktemp --tmpdir proxy.XXXXXXXXXX)" trap "rm -f $TMPFILE" 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15 eval $cmd <"$file" >$TMPFILE cat $TMPFILE >"$file" rm -f $TMPFILE trap - 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15