我只是注意到,在我的一台机器上(运行 Debian Sid),每当我输入ls任何带空格的文件名时,它周围都有单引号。
我立即检查了我的别名,却发现它们完好无损。
wyatt@debian630:~/testdir$ ls
'test 1.txt' test1.txt
wyatt@debian630:~/testdir$ alias
alias ls='ls --color=auto'
alias wget='wget --content-disposition'
wyatt@debian630:~/testdir$
Run Code Online (Sandbox Code Playgroud)
另一个测试,文件名中包含单引号(也回答了 jimmij 的请求):
wyatt@debian630:~/testdir$ ls
'test 1.txt' test1.txt 'thishasasinglequotehere'\''.txt'
wyatt@debian630:~/testdir$ touch "'test 1.txt'"
wyatt@debian630:~/testdir$ ls
''\''test 1.txt'\''' test1.txt
'test 1.txt' 'thishasasinglequotehere'\''.txt'
Run Code Online (Sandbox Code Playgroud)
使用新的 coreutils-8.26 输出进行更新(诚然,这不那么令人困惑,但默认情况下仍然令人恼火)。感谢 Pádraig Brady 提供此打印输出:
$ ls
"'test 1.txt'" test1.txt
'test 1.txt' "thishasasinglequotehere'.txt"
$ ls -N
'test 1.txt' test1.txt
test 1.txt thishasasinglequotehere'.txt
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我如何正确停止它?
需要明确的是,我自己将 ls 设置为自动彩色输出。它从来没有在事物周围加上引号。
我正在运行bash,coreutils 8.25。
有什么方法可以在不重新编译的情况下解决这个问题?
编辑:出现 coreutils 开发人员选择)打破惯例并将其设为全局默认值。 …
在大多数 shellnullglob中不是默认的。这意味着,例如,如果您运行此命令
ls *
Run Code Online (Sandbox Code Playgroud)
在一个空目录中,它会将*glob扩展为一个 literal *,而不是一个空的参数列表。有一些方法可以改变这种行为,这样*在一个空目录中将返回一个空的参数列表,这看起来更直观。
那么,是否有理由nullglob默认禁用?如果是,那是什么原因?
如果我ls在主目录中使用该命令,则每一行输出都有一个前导空格:
$ ls
bin Documents ...
Run Code Online (Sandbox Code Playgroud)
它似乎只对我的主目录执行此操作。
它为什么这样做?
注意:我不认为这与为什么 'ls' 突然用单引号括起空格的项目重复?因为那不是我问的问题,我也不想知道答案。仅仅知道空格是引用的副作用就足以回答我的问题。