#!/bin/sh # inplace iconv wrapper # # (c) Michael Shigorin , 2022 # GPLv2 with ukronazi exception: those supporting them better hide tmpfile="$(mktemp)" atexit() { rm -f "$tmpfile"; } trap atexit HUP INT QUIT args= file= for i in "$@"; do case "$i" in -l|--list|-\?|--help|--usage|-V|--version) exec iconv "$i";; -s|--silent) shift ;; -f|-t) shift args="$args $i $1" shift ;; -f*|-t*|--f*|--t*|-c) args="$args $i" shift ;; -o|-*) echo "$0: unsupported option \`$i'" >&2 exit 1 ;; *) file="$1" break ;; esac done [ -f "$file" ] || { echo "$0: $file does not exist" >&2 exit 2 } iconv $args < "$file" > "$tmpfile" && touch -r "$file" "$tmpfile" && mv "$tmpfile" "$file"