bash:摆脱'.' 当循环遍历以'.'开头的文件时'和'..' 在一个文件夹中

the*_*osp 2 bash shell glob

我想循环以'.'开头的文件.在目录x中(x可能是任何路径):

$ for file in x/.*
> do
>     echo -n $file" "
> done
x/. x/.. x/..a x/.b
Run Code Online (Sandbox Code Playgroud)

什么是摆脱x /.和x/..的最佳方法?

gho*_*g74 5

用bash,你可以使用 GLOBIGNORE

$ ls -1tra
..
.test1
.test
test
.

$ for i in .*; do echo $i;done
.
..
.test
.test1

$ GLOBIGNORE=".:.."
$ for i in .*; do echo $i;done
.test
.test1
Run Code Online (Sandbox Code Playgroud)