path="/from/here/to/there.txt"
dir="${path%/*}" # sets dir to '/from/here/to' (equivalent of dirname)
last_dir="${dir##*/}" # sets last_dir to 'to' (equivalent of basename)
This is more efficient since no external commands are used.
The top answer is absolutely correct for the question asked. In a more generic case with the needed directory in the middle of a long path, this approach leads to a hard to read code. For example :