Bash#

#!/bin/bash                                                                     

pathname=/home/username/foo.txt
dir=${pathname%/*}
file=${pathname##*/}

echo -e "dir:$dir"
echo -e "file:$file"

Linux.Shell - Mac.Shell