bash脚本中的通配符扩展

bash脚本中的通配符扩展,bash,Bash,如果我在脚本中写入此字符串: list=$(ls /path/to/some/files/*/*/*.dat) 它很好用。但我需要的是 files="files/*/*/*.dat" list=$(ls /path/to/some/${files}) 上面写着 ls: /path/to/some/files/*/*/*.dat: No such file or directory 我应该怎么做?试试这个: list=$(find /path/to/some/files/ -mindepth

如果我在脚本中写入此字符串:

list=$(ls /path/to/some/files/*/*/*.dat)
它很好用。但我需要的是

files="files/*/*/*.dat"
list=$(ls /path/to/some/${files})
上面写着

ls: /path/to/some/files/*/*/*.dat: No such file or directory
我应该怎么做?

试试这个:

list=$(find /path/to/some/files/ -mindepth 3 -maxdepth 3 -name '*.dat')

如果您只在没有匹配的
.dat
文件的情况下收到该消息,请将其添加到脚本中:

shopt -s nullglob

如果没有匹配的文件,它将导致glob扩展为空列表,而不是按字面意思处理。

对我有效…只有在没有.dat文件时才会失败。您将如何处理
$list
?解析
ls
的输出通常不是正确的方法。我需要将此列表分成几个文件,每个文件中有N个文件,然后在集群中的多台计算机上启动单独的作业,每个作业有N个输入文件。使用find是一个好方法,但这将生成一个文件名字符串,如果这些文件名包含空格,则会中断。