ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Michael Shigorin <mike@altlinux.org>
To: devel@lists.altlinux.org
Subject: [devel] iconv-i
Date: Fri, 23 Sep 2022 17:17:13 +0300
Message-ID: <20220923141713.GX10489@imap.altlinux.org> (raw)

[-- 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"

             reply	other threads:[~2022-09-23 14:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 14:17 Michael Shigorin [this message]
2022-09-23 15:13 ` [devel] Administrivia Dmitry V. Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220923141713.GX10489@imap.altlinux.org \
    --to=mike@altlinux.org \
    --cc=devel@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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