Extract file basename without path and extension in bash [duplicate]
You don’t have to call the external basename command. Instead, you could use the following commands: $ s=/the/path/foo.txt $ echo “${s##*/}” foo.txt $ s=${s##*/} $ echo “${s%.txt}” foo $ echo “${s%.*}” foo Note that this solution should work in all recent (post 2004) POSIX compliant shells, (e.g. bash, dash, ksh, etc.). Source: Shell Command Language … Read more