我需要检查一些可能存在的文件
- 名称中包含空格
- 在其名称中包含非 ASCII(例如,元音变音符号)
由于我使用的空格String::ShellQuote
。但是,在 OSX 上执行时,这似乎不适用于 Umlauts(尚不了解其他操作系统):
# vim: ft=perl fenc=utf8
# perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level
use strict;
use warnings;
use String::ShellQuote;
my @files = map {$_, shell_quote($_)} ("AOU.tmp", "ÄÖÜ.tmp", "A OU.tmp", "Ä ÖU.tmp");
foreach my $file ( @files, ) {
print "$file:\t";
`touch $file`;
print "created, " if( !$? ) ;
print "EXISTS (says Perl), " if( -e $file );
`ls -1 $file >/dev/null`;
print "EXISTS (says ls), " if( !$? );
print "\n";
}
输出:
OU.tmp: created, EXISTS (says Perl), EXISTS (says ls),
AOU.tmp: created, EXISTS (says Perl), EXISTS (says ls),
ÄÖÜ.tmp: created, EXISTS (says Perl), EXISTS (says ls),
'ÄÖÜ.tmp': created, EXISTS (says ls),
A OU.tmp: created, EXISTS (says Perl), EXISTS (says ls),
'A OU.tmp': created, EXISTS (says ls),
Ä ÖU.tmp: created, EXISTS (says Perl), EXISTS (says ls),
'Ä ÖU.tmp': created, EXISTS (says ls),
问题:如何可靠地 shell_quote 可能包含扩展字符的文件名?
旁注:我认为这是非常好的 OS-X 典型 UTF8 规范化问题之一(变音符号的预组合与分解编码)。尽管如此,我认为String::ShellQuote
应该能够处理它。