Get the file name from a path without basename
Get the last part of a path in Bash with ${p##*/} instead of calling basename. It runs inside the shell, and it behaves differently on a trailing slash.
You have a path and want only the file name, and calling basename in a loop over thousands of paths is slower than it needs to be.
p=/var/log/nginx/access.log
printf '%s\n' "${p##*/}"
printf '%s\n' "$(basename "$p")"
p=/var/log/nginx/
printf 'expansion: [%s]\n' "${p##*/}"
printf 'basename: [%s]\n' "$(basename "$p")"access.log
access.log
expansion: []
basename: [nginx]${p##*/} removes the longest prefix that ends in a slash, which leaves the last component. It is shell parameter expansion, so no process is started. That matters inside a loop, where each basename call is a fork and an exec.
The two are not equal on a path with a trailing slash. basename ignores it and returns nginx, while the expansion returns an empty string. Strip trailing slashes first with p=${p%/} when the input may carry one.