Get the newest directory to a variable in Bash July 23, 2023 by Tarik BACKUPDIR=$(ls -td /backups/*/ | head -1) $(...) evaluates the statement in a subshell and returns the output.