I'm writing a shell script to automate the restore of a database backup. As part of this I need to know the name of the directory conataining the backup files. However this will change every time.
How can I get the directory name into a variable for reference later on.
example: I have the basic directory:
/var/backups/db/
In here there will be another directory, whose name will change every time (e.g. /var/backups/db/db_backup_109245_abc/
)
How can I get the directory name (e.g. db_backup_109245_abc
) including the full path into a variable so I can refer to it later on?
There will only ever be one directory in here (an earlier part of the process guarantees that), and the name of that directory will vary every time.
$variable="db_backup_109245_abc"
. What else do you need? – terdon Apr 20 '20 at 16:06/var/backups/db/X
instead of/var/backup/db/Y
? What's the logic behind what subdirectory you should use? Is it the one with the most recently added file in it, the one that sorts before or after all others, the one with the highest number in its name? – Kusalananda Apr 20 '20 at 16:22