简体   繁体   中英

Get basename from path in env variables using a Bash script

I need to get the basename from the env variable which I am doing like example my basePath is basePath="x/y/z/t" and I want t, I am doing like:

$(basename $basePath)

but it is not helpful.

Similarly, I want to get the latest updated folder/file from that path which I am doing like:

$(basename $(ls -td '$basePath'/*/ | head -n1))

but this is also not helpful.

Try the following:

basePath="x/y/z/t"

# Find latest files modified in the last 24 Hours
find ${basePath/*\/} -type f -mtime +1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM