如何从具有可变文件名的查找中获取文件路径

How to obtain file path from find with variable filename

我有一个命令可以正常工作:

fname=$(find $dir -name '*001.txt')

我想做的是用变量替换数字:

fname=$(find $dir -name '*$num.txt')

却一无所获。我试过转义单引号:\'*$num.txt\',将单引号括在双引号中:"'"*$num.txt"'", 但没有任何效果。我需要什么?

试试这个:

fname=$(find $dir -name "*${num}.txt")