Reputation: 3028
I've got a batch file like
for f in bin/$1*.txt; do echo $f; done
I'd like to echo just the filename - not bin/temp.txt or temp.txt - just temp.
How I can extract the filename from $f?
Upvotes: 0
Views: 62
Reputation: 15418
Parameter expansion.
$: 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
Upvotes: 0
Reputation:
If the suffix is always the same you can just use basename -s ".txt" $f
.
Upvotes: 1