为什么 ls 仍然显示通过 GLOBIGNORE 排除的文件?

Boj*_*kić 2 shell bash

文件丢失echo但存在ls -a。为什么?

bojan@hyperion:~$ touch .ignoramus
bojan@localhost:~$ ls -al | grep ignor
-rw-rw-r--  1 bojan bojan     0 Apr 19 19:05 .ignoramus
bojan@localhost:~$ GLOBIGNORE=".ignoramus";
bojan@localhost:~$ echo .i*
.icons
bojan@localhost:~$ ls -al | grep ignor
-rw-rw-r--  1 bojan bojan     0 Apr 19 19:05 .ignoramus
bojan@localhost:~$ echo $GLOBIGNORE
.ignoramus
Run Code Online (Sandbox Code Playgroud)

ls man 说-a只显示隐藏,没有提到 GLOBIGNORE。

   -a, --all
          do not ignore entries starting with .

ls (GNU coreutils) 8.23
GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)
Run Code Online (Sandbox Code Playgroud)

Gil*_*il' 5

设置GLOBIGNORE对 没有影响lsls说明书也没有提到GLOBIGNORE,因为ls不关心GLOBIGNORE。它只是 bash 的一个特性,这使得它在 glob 模式中省略了一些文件。

使用echo .i*, bash 列出文件,因此GLOBIGNORE开始。使用ls -a,ls列出文件,因此GLOBIGNORE无关紧要。

GNUls有一个类似的特性:你可以传递一个模式作为命令行选项来忽略。

ls -a -I .ignoramus
Run Code Online (Sandbox Code Playgroud)