[英]Extract the filename from a script variable
我有一個批處理文件,例如
for f in bin/$1*.txt; do echo $f; done
我只想回顯文件名-不回聲bin / temp.txt或temp.txt-只是回聲。
如何從$ f中提取文件名?
如果后綴始終相同,則可以使用basename -s ".txt" $f
。
參數擴展。
$: f=bin/temp123.txt # an example you might have
$: x="${f#bin/}" # asign to x without bin/ prefix
$: echo $x
temp123.txt
$: echo ${x%.txt} # show x without .txt suffix
temp123
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.