在终端中,我可以运行...
find . -type f -print0
./testdir/testfile2.txt./testdir/testfile.txt
Run Code Online (Sandbox Code Playgroud)
进而...
find . -type f -printf "%p\0"
./testdir/testfile2.txt./testdir/testfile.txt
Run Code Online (Sandbox Code Playgroud)
它们在视觉上看起来相同,但由于这是关于空字符,所以并没有说明太多。如果我通过 ruby repl 运行:
2.5.1 :001 > `find . -type f -print0`
=> "./testdir/testfile2.txt\u0000./testdir/testfile.txt\u0000"
Run Code Online (Sandbox Code Playgroud)
进而
2.5.1 :002 > `find . -type f -printf "%p\0"`
Traceback (most recent call last):
3: from /usr/share/rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
2: from (irb):2
1: from (irb):2:in ``'
ArgumentError (string contains null byte)
Run Code Online (Sandbox Code Playgroud)
-print0
选项输出的内容与 有什么区别printf
?
测试系统信息:
姓名: Linux XPS-15-9570 4.15.0-30-generic #32-Ubuntu SMP Thu Jul 26 17:42:43 UTC 2018 x86_64 x86_64 …