Version 1:
getProfile() {
CURRENT_PATH=$(pwd)
oldIFS="$IFS" # Save the old value of IFS
IFS="/" # Set IFS to the new delimiter
# Split the string into an array of substrings
read -ra array <<<"$CURRENT_PATH"
IFS=oldIFS
PROFILE=${array[-2]}
echo "${PROFILE}"
}
Version 2:
get_profile() {
script_dir="$(dirname "$0")"
# https://stackoverflow.com/questions/71224944/how-to-get-the-name-of-the-grandparent-directory
profile=$(basename -- "$(realpath -m -- "$script_dir/..")")
echo "${profile}"
}