[英]Why echo command doesn't list directory contents when read * (asterisk) from CRLF file?
有两个文件:
file1.txt-在Linux上创建
root@localhost:~# file file1.txt
file1.txt: ASCII text
root@localhost:~# od -c file1.txt
0000000 * \n
file2.txt-在Windows上创建
root@localhost:~# file file2.txt
file1.txt: ASCII text, with CRLF line terminators
root@localhost:~# od -c file2.txt
0000000 * \r \n
root@localhost:~# ls
myFile1 myFile2 myFile3
root@localhost:~# echo `cat file1.txt`
myFile1 myFile2 myFile3
root@localhost:~# echo `cat file2.txt`
*
为什么第二个文件中的CR(回车)会导致echo命令不列出目录内容,而只显示星号?
以与echo *.txt
显示所有以.txt
结尾的文件相同的方式, echo *$'\\r'
显示所有以回车结尾的文件。
由于您没有任何内容,因此显示逐字模式
如果您手动或通过使用DOS行终止符运行脚本来创建一些脚本,它们将显示:
$ touch $'foo\r' $'bar\r'
$ echo *$'\r' | hexdump -C
00000000 62 61 72 0d 20 66 6f 6f 0d 0a |bar. foo..|
0000000a
(如果没有hexdump
,则回车将导致输出反复覆盖自身,使其看起来已损坏或仅匹配一个文件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.