iconvで「シフトJIS」を変換する際にハマった
「シフトJIS」で保存された、バックスラッシュ(0x5c)を含むファイルをiconvで変換するときにしばらくハマった。
$ iconv --version iconv (GNU libc) 2.17 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Ulrich Drepper. $ for enc in Shift-JIS Shift_JIS Shift_JISX0213 SJIS SJIS-win Windows-31J CP932 ; do echo -n '\' | iconv -f ${enc} -t UTF-8 | od -cx done
結果。
0000000 302 245 a5c2 0000002 0000000 302 245 a5c2 0000002 0000000 302 245 a5c2 0000002 0000000 302 245 a5c2 0000002 0000000 \ 005c 0000001 0000000 \ 005c 0000001 0000000 \ 005c 0000001
ずっと"Shift_JIS"を指定していて、どうしても円記号(U+00A5)になるなぁ、逆斜線(U+005C)が欲しいのに、とハマっていた。 "SJIS-win"か"Windows-31J"か"CP932"を指定しないといけなかったという教訓。
参考