文件名扩展在bash中无法理解

zui*_*tje 2 bash shell glob

我有以下代码:

#!/bin/sh

LOG="myfile.log"

ls -l "${LOG}_*"

find . -type f -name "${LOG}_*" -exec ls -l {} \;
Run Code Online (Sandbox Code Playgroud)

产生以下输出:

$ ./test.sh

ls: cannot access myfile.log_*: No such file or directory

-rw-r--r--. 1 user user 0 Sep 26 23:03 ./myfile.log_20150926_1928
-rw-r--r--. 1 user user 0 Sep 26 23:03 ./myfile.log_20150926_1926
-rw-r--r--. 1 user user 0 Sep 26 23:03 ./myfile.log_20150926_1930
-rw-r--r--. 1 user user 0 Sep 26 23:03 ./myfile.log_20150926_1927
-rw-r--r--. 1 user user 0 Sep 26 23:03 ./myfile.log_20150926_1929
Run Code Online (Sandbox Code Playgroud)

我不明白为什么"find"命令工作而不是"ls"

干杯

cho*_*oba 5

Shell仅在未引用时扩展星号.

Find会自动扩展通配符-name,您通常必须引用它们以防止shell扩展它们.