それは私を狂ってしまう。次のbashスクリプトを用意してください。でも、(Cygwinがインストールされている)は、Windows 7は、スクリプトを実行すると正しい結果を与えるでユニコードのファイル名を使用した移植可能な(クロスプラットフォームの)スクリプト
Creating a testing directory: ./test.64511
Creating a file word.txt with content á.txt
The word.txt contains:á.txt
creating a file á.txt with a touch
total 1
-rw-r--r-- 1 clt clt 7 3 júl 12:51 word.txt
-rw-r--r-- 1 clt clt 0 3 júl 12:51 á.txt
command: bash cycle
á.txt is a file
command: find . -name á.txt -print
./á.txt
command: find . -type f -print | grep á.txt
./á.txt
command: find . -type f -print | fgrep -f word.txt
./á.txt
:
testdir="./test.$$"
echo "Creating a testing directory: $testdir"
mkdir "$testdir"
cd "$testdir" || exit 1
echo "Creating a file word.txt with content á.txt"
echo 'á.txt' > word.txt
fname=$(cat word.txt)
echo "The word.txt contains:$fname"
echo "creating a file $fname with a touch"
touch $fname
ls -l
echo "command: bash cycle"
while read -r line
do
[[ -e "$line" ]] && echo "$line is a file"
done < word.txt
echo "command: find . -name $fname -print"
find . -name $fname -print
echo "command: find . -type f -print | grep $fname"
find . -type f -print | grep "$fname"
echo "command: find . -type f -print | fgrep -f word.txt"
find . -type f -print | fgrep -f word.txt
FreeBSD上で
(そしておそらくあまりにもLinux上)
は結果を与えます。しかし、私はOS Xはbash上でこのスクリプトを実行し、この得た:だから
Creating a testing directory: ./test.32534
Creating a file word.txt with content á.txt
The word.txt contains:á.txt
creating a file á.txt with a touch
total 8
-rw-r--r-- 1 clt staff 0 3 júl 13:01 á.txt
-rw-r--r-- 1 clt staff 7 3 júl 13:01 word.txt
command: bash cycle
á.txt is a file
command: find . -name á.txt -print
command: find . -type f -print | grep á.txt
command: find . -type f -print | fgrep -f word.txt
を、唯一bash
はファイルá.txt
なし、find
もgrep
を見つけました。 :(ファイル名を変換するためのiconv
を使用するapple.stackexchangeとone answer suggestingに最初に尋ねた。
$ find . -name $(iconv -f utf-8 -t utf-8-mac <<< á.txt)
これは、「OSのX」のための作品ですが、それはとにかくひどいですが
が。(別のものを入力して必要。端末にどのような着信するすべてのutf8文字列のためのコマンド)
私は、一般的なクロスプラットフォームのbashのプログラミング解決策を見つけるためにしようとしているので、質問は次のとおりです。
- OS Xの場合、
bash
はファイルが見つかりましたが、find
は見つかりませんでしたか?
と
- Unicodeのファイル名がファイルに保存されているクロスプラットフォームのbashスクリプトの書き方。
- のみソリューションは
iconv
で特別バージョンのみOS Xのために書くのですか? - は、
perl
のような他のスクリプト言語のための移植可能なソリューションですか?
シモンズ:そして最後に、実際に質問をプログラミングするが、コマンドラインutf8
EDIT
とうまく再生されないものを分解したファイル名を使用して、Appleの決断の根拠は何か不思議に思っていませんシンプルod
。検索から
$ ls | od -bc
0000000 141 314 201 056 164 170 164 012 167 157 162 144 056 164 170 164
a ́ ** . t x t \n w o r d . t x t
0000020 012
\n
と
$ od -bc word.txt
0000000 303 241 056 164 170 164 012
á ** . t x t \n
0000007
ので
$ while read -r line; do echo "$line" | od -bc; done < word.txt
0000000 303 241 056 164 170 164 012
á ** . t x t \n
0000007
とoutpoutのでls
$ find . -print | od -bc
0000000 056 012 056 057 167 157 162 144 056 164 170 164 012 056 057 141
. \n . / w o r d . t x t \n . / a
0000020 314 201 056 164 170 164 012
́ ** . t x t \n
と同じで、word.txt
の内容が異なっているものをファイルそのコンテンツから作成されます。したがって、まだbash
がファイルを見つけた理由を説明できません。
したがって、 'bash'( OS X)は、ファイル名を分解した 'á'やfind、grepなどの他のユーティリティを探しているときに、あらかじめ作成された'á'を内部的に正しく変換します。だから、 "移植可能な"スクリプトを書いているのは、可能であれば "純粋なbash"だけを使っているのです...そうですか? – jm666
*したがって、bash(OS X用にコンパイルされたもの)は、内部的にprecomposedá*を変換するのはなぜですか?私はソースを見ていないが、それは正しいことだ。 –
OK、答えを受け入れる - 主に: "ユニコードは難しい"と "ソフトウェアは駄目です" :) :) - 私の追加:ほとんどのOSは、ソフトウェアは、19世紀のレベルであり、ユーザーのニーズについては何も知らない。 Shigh。ありがとう:) – jm666