同じコマンド:echo 1 > filename
異なるファイル名を作成します:
$ sh -c 'echo $LANG >=с=.sh' && ls *.sh | od -c
0000000 = 321 = . s h \n
0000007
と
$ bash -c 'echo $LANG >=с=.bash' && ls *.bash | od -c
0000000 = 321 201 = . b a s h \n
0000012
文字はどこс
にありますかU+0441
— CYRILLIC SMALLLETTERES。エンコーディングsh
の2番目のバイトを消費することは明らかです。utf-8
$ ls *sh
=?=.sh =с=.bash
$LANG
どちらの場合も:
$ cat *sh
en_US.utf8
en_US.utf8
sh
私のシステムにリンクさdash
れています:
$ apt-cache show dash | grep -i version
Version: 0.5.5.1-7ubuntu1
stty iutf8
が設定されます。
dash
マルチバイト文字を壊さないようにする設定はありますか?
マニュアルに文字エンコードについての言及はありません:
$ man dash | grep -i encoding
$ man dash | grep -Pi 'multi.*byte'
アップデート
utf-8エンコーディングの文字
の2番目のバイト'\201'
は、 Cではsigned char(またはunsigned char)です。'с'
-127
129
ソースコード(apt-get source dash
)で検索すると、次のようになり-127
ます。
src/parser.h:38:#define CTL_FIRST -127 /* first 'special' character */
src/parser.h:39:#define CTLESC -127 /* escape next character */
次のフラグメントにつながるマクロへのCTLESC
リードを検索します。rmescapes()
src/expand.c:expandarg()
/*
* TODO - EXP_REDIR
*/
if (flag & EXP_FULL) {
ifsbreakup(p, &exparg);
*exparg.lastp = NULL;
exparg.lastp = &exparg.list;
expandmeta(exparg.list, flag);
} else {
if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
rmescapes(p);
sp = (struct strlist *)stalloc(sizeof (struct strlist));
sp->text = p;
*exparg.lastp = sp;
exparg.lastp = &sp->next;
}
TODO
そしてXXX
、より新しいバージョンが役立つかもしれないことを示唆しています。debian/dash.README.source
に指差す:
$ git clone http://smarden.org/git/dash.git/
$ cd dash
2つのブランチがあります:
$ git br
* debian-sid
release+patches
エスケープdebian-sid
バイトで削除されます。release+patches
ブランチで欠落しgrep
ているバイトを見つけます。
$ ./configure
$ make && rm *.dash -f; ./dash -c 'echo 1 >fсf.dash' &&
> ls *.dash | od -c | grep 201
git diff debian-sid...release+patches
rmescapes()
で削除されたことを示していますrelease-patches
:
diff --git a/src/expand.c b/src/expand.c
index e4c4c8b..f2f964c 100644
--- a/src/expand.c
+++ b/src/expand.c
...
@@ -213,8 +210,6 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
exparg.lastp = &exparg.list;
expandmeta(exparg.list, flag);
} else {
- if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
- rmescapes(p);
sp = (struct strlist *)stalloc(sizeof (struct strlist));
sp->text = p;
*exparg.lastp = sp;
@@ -412,7 +407,7 @@ lose:
}
これらの変更がdash 0.5.6.1
Ubuntuに含まれるかどうかは不明です。
今のところ、コマンドを作成する唯一の方法は次のとおりです。
$ sh -c 'echo 1 >fсf.dash' && ls *.dash | od -c | grep 201
動作することは、次のように再構成sh
することbash
です。
$ sudo dpkg-reconfigure dash
他に選択肢はありますか?