Bash getting the parent folder name from a bash defined variable

Problem

You have defined a variable in a bash script (ie MY_FOLDER) but you also want to dynamically get the parent folder (ie MY_FOLDER can have multiple values).

Solution

Use the dirname as in the following

MY_FOLDER=/home/user/first_folder/second_folder
MY_PARENT_FOLDER=$(dirname $MY_FOLDER)

echo $MY_FOLDER
echo $MY_PARENT_FOLDER

.......
/home/user/first_folder/second_folder
/home/user/first_folder