【发布时间】:2013-07-05 16:35:24
【问题描述】:
我知道我有一个文件。
我知道这个文件是 Hello.txt,或 HeLLo.txt,或 HELLo.txt,或其他大小写变体
所以我可以通过以下方式找到这个文件:
find . -iname hello.txt
它找到了。
如何将真实姓名(“HelLO.txt”)放入 linux 变量中?
【问题讨论】:
我知道我有一个文件。
我知道这个文件是 Hello.txt,或 HeLLo.txt,或 HELLo.txt,或其他大小写变体
所以我可以通过以下方式找到这个文件:
find . -iname hello.txt
它找到了。
如何将真实姓名(“HelLO.txt”)放入 linux 变量中?
【问题讨论】:
var=`find . -iname hello.txt | head -n1 | sed 's/.*\///g'`
应该做你想做的。
【讨论】:
最简单的方法:
var=`find . -iname hello.txt`
请注意,这会将所有匹配的文件名分配给变量,因此如果您有多个变体(Hello HeLLO hello HELLO 等...),您将在 var 中获得所有变体。
【讨论】: