Bash - How to get the name a folder inside the current folder?

bash, directory, shell

Solution

Assuming there is exactly one subdirectory:

dir=$(find . -mindepth 1 -maxdepth 1 -type d)

If you don't have GNU find, then

for f in *; do [[ -d "$f" ]] && { dir=$f; break; }; done

Problem

Let's say my script is running inside a folder, and in this folder is anther folder with a name that can change each time I run the script. How can I find the name of that folder ? Edit : As an example, let's say my script is running in the folder `/testfolder`, which is known and does not change. In `/testfolder` there is another folder : `/testfolder/randomfolder`, which is unknown and can change. How do I find the name of `/randomfolder` ? I hope it's clearer, sorry for the confusion.

Original source