I have directory structure like this
MainDIR/DIr2/b.txt
MainDIR/DIr1/a.txt
I want to get only base file names, like a.txt and b.txt
To get the basename of a file path, which is stored in a shell variable MYFILE
, you can do it like this:
In Zsh it is easiest, because you don't need to create a separate process:
$MYFILE:t
in bash (and, I think, ksh), the only method I know is
$(basename $MYFILE)
This works in Zsh too, but has the drawback that a sub-process is needed.
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.