如果glob */只匹配目录,那么逻辑上!(*/)应该匹配非目录;但这不起作用。这是一个bug,还是我漏掉了什么?这在任何shell上都能工作吗?
测试1以证明*/工作正常
$ cd /tmp; ls -ld */
drwxr-xr-x 2 seand users 4096 Jan 1 15:59 test1//
drwxr-xr-x 2 seand users 4096 Jan 1 15:59 test2//
drwxr-xr-x 2 seand users 4096 Jan 1 15:59 test3//测试2以显示!(*/)的潜在错误
$ cd /tmp; shopt -s extglob; ls -ld !(*/)
/bin/ls: cannot access !(*/): No such file or directory发布于 2012-01-05 08:13:36
具体问题的答案已经给出了;我不确定您是否真的想要另一个解决方案,或者您只是对分析行为感兴趣,但是列出当前文件夹中所有非目录的一种方法是使用find:
find . ! -type d -maxdepth 1https://stackoverflow.com/questions/8696462
复制相似问题