Extract File Basename Without Path and Extension in Bash

Posted by neversaint on Stack Overflow See other posts from Stack Overflow or by neversaint
Published on 2010-04-19T01:25:28Z Indexed on 2010/04/19 1:33 UTC
Read the original article Hit count: 298

Filed under:
|
|
|

Given file names like these:

/the/path/foo.txt
bar.txt

I hope to get

foo
bar

Why this doesn't work?

#!/bin/bash

fullfile=$1
fname=$(basename $fullfile)
fbname=${filename%.*}
echo $fbname

What's the right way to do it?

© Stack Overflow or respective owner

Related posts about unix

Related posts about linux