#/usr/bin/env bash DIRECTORY="/home/user/example/foo/bar" BASE_DIRECTORY=$(echo "$DIRECTORY" | cut -d "/" -f2) echo "#$BASE_DIRECTORY#";