hpe*_*sen 2 bash wildcard find
我find没有按照我的预期工作.当有多个文件时,它会因错误而停止.
hpek@melda:~/temp/test$ ll
total 16
-rw-r--r-- 1 hpek staff 70B Mar 2 15:16 f1.tex
-rw-r--r-- 1 hpek staff 70B Mar 2 15:17 f2.tex
hpek@melda:~/temp/test$ find . -name *.tex
find: f2.tex: unknown option
hpek@melda:
Run Code Online (Sandbox Code Playgroud)
如果我删除其中一个文件,它的工作原理如下:
hpek@melda:~/temp/test$ rm f1.tex
hpek@melda:~/temp/test$ find . -name *.tex
./f2.tex
hpek@melda:~/temp/test$
Run Code Online (Sandbox Code Playgroud)
我删除的文件无关紧要.只要通配符提供了多个文件,就会find暂停.
*.tex 在作为参数发送到命令之前由bash扩展.
find . -name *.tex
Run Code Online (Sandbox Code Playgroud)
在你的情况下相当于
find . -name f1.tex f2.tex
Run Code Online (Sandbox Code Playgroud)
解决方案:"..."使用通配符放置参数以避免shell扩展:
find . -name "*.tex"
Run Code Online (Sandbox Code Playgroud)
这将按预期工作:
$ find . -name "*.tex"
./f1.tex
./f2.tex
Run Code Online (Sandbox Code Playgroud)