同じコマンド: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)です。'с'-127129
ソースコード(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+patchesrmescapes()で削除されたことを示しています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.1Ubuntuに含まれるかどうかは不明です。
今のところ、コマンドを作成する唯一の方法は次のとおりです。
$ sh -c 'echo 1 >fсf.dash' && ls *.dash | od -c | grep 201
動作することは、次のように再構成shすることbashです。
$ sudo dpkg-reconfigure dash
他に選択肢はありますか?