简体   繁体   English

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

[英]How to obtain file path from find with variable filename

I have a command that works fine as is: 我有一个可以正常工作的命令:

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

What I would like to do is replace the number by a variable: 我想做的是用一个变量替换数字:

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

but get nothing. 但一无所获。 I have tried escaping the single quotes: \\'*$num.txt\\' , enclosing the single quotes in double quotes: "'"*$num.txt"'", but nothing works. 我尝试转义单引号: \\'*$num.txt\\' ,将单引号括在双引号中: "'"*$num.txt"'",但没有任何效果。 What do I need? 我需要什么?

尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM