Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 为什么echo命令没有';从CRLF文件读取*(星号)时是否列出目录内容?_Bash_Shell_Echo - Fatal编程技术网

Bash 为什么echo命令没有';从CRLF文件读取*(星号)时是否列出目录内容?

Bash 为什么echo命令没有';从CRLF文件读取*(星号)时是否列出目录内容?,bash,shell,echo,Bash,Shell,Echo,有两个文件: 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@localho

有两个文件:

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


为什么第二个文件中的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

(如果没有
hextump
,回车将导致输出重复覆盖自身,使其看起来损坏或仅匹配了一个文件)

这是imo的预期行为。键入
echo*
echo*\\r
(第二个echo的语法可能依赖于分布。这是在OSX上测试的)在Debian上检查:
echo*\\r
返回
*\r
在Debian上,语法可能类似于
echo-e*\r
$ touch $'foo\r' $'bar\r'

$ echo *$'\r' | hexdump -C
00000000  62 61 72 0d 20 66 6f 6f  0d 0a                    |bar. foo..|
0000000a