#!/bin/bash # Strip the path s="/the/path/foo.txt" echo ${s##*/} # Will output: foo.txt # Strip the extension s="foo.txt" echo echo ${s%.*} # will output: foo