ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] iconv-i
@ 2022-09-23 14:17 Michael Shigorin
  2022-09-23 15:13 ` [devel] Administrivia Dmitry V. Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Shigorin @ 2022-09-23 14:17 UTC (permalink / raw)
  To: devel

[-- Attachment #1: Type: text/plain, Size: 235 bytes --]

	Здравствуйте.
Понадобилась тут обёртка вокруг iconv по аналогии с sed -i
(перекодирование по месту); вдруг ещё кому пригодится.

-- 
 ---- WBR, Michael Shigorin / http://altlinux.org
  ------ http://opennet.ru / http://anna-news.info

[-- Attachment #2: iconv-i --]
[-- Type: text/plain, Size: 734 bytes --]

#!/bin/sh
# inplace iconv wrapper
#
# (c) Michael Shigorin <mike@altlinux.org>, 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"

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-23 15:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23 14:17 [devel] iconv-i Michael Shigorin
2022-09-23 15:13 ` [devel] Administrivia Dmitry V. Levin

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git