echo用\ x20替换\ x09

0 perl

一位同事注意到,在创建具有特定非打印字符的文件时,perl会替换它们.在这种情况下,\ x09被替换为\ x20.

echo `perl -e 'print "\x41"x40 . "\xc4\x09\x40"'` > test.out
Run Code Online (Sandbox Code Playgroud)

查看生成的文件时:

xxd test.out
Run Code Online (Sandbox Code Playgroud)

你看:

0000000: 4141 4141 4141 4141 4141 4141 4141 4141  AAAAAAAAAAAAAAAA
0000010: 4141 4141 4141 4141 4141 4141 4141 4141  AAAAAAAAAAAAAAAA
0000020: 4141 4141 4141 4141 c420 400a            AAAAAAAA. @.
Run Code Online (Sandbox Code Playgroud)

请注意,最后3个字节是\ xc4,\ x20,\ x40而不是\ xc4,\ x09,\ x40.没有人能够向我们解释这个.获取\ x09的唯一方法是使用十六进制编辑器手动编辑test.out文件.有什么想法吗?

Mar*_*eed 5

那是shell,而不是Perl.如果引用命令替换,则将保留选项卡:

echo "$(perl -e 'print "\x41"x40 . "\xc4\x09\x40"')"  > test.out
Run Code Online (Sandbox Code Playgroud)

但我不知道你为什么要在这里涉及贝壳.最好echo完全退出并直接将perl运行到文件中.这意味着perl输出必须包含自己的换行符,但您可以通过多种方式执行此操作:

perl -e 'print "\x41"x40 . "\xc4\x09\x40\n"' > test.out
Run Code Online (Sandbox Code Playgroud)

要么

perl -le 'print "\x41"x40 . "\xc4\x09\x40"' > test.out
Run Code Online (Sandbox Code Playgroud)

要么

perl -E 'say "\x41"x40 . "\xc4\x09\x40"' > test.out
Run Code Online (Sandbox Code Playgroud)