separate file and path in bash?
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Droplet of life
--
Chapters
00:00 Separate File And Path In Bash?
00:15 Accepted Answer Score 14
00:26 Answer 2 Score 30
00:36 Thank you
--
Full question
https://superuser.com/questions/443859/s...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #bash #path
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Droplet of life
--
Chapters
00:00 Separate File And Path In Bash?
00:15 Accepted Answer Score 14
00:26 Answer 2 Score 30
00:36 Thank you
--
Full question
https://superuser.com/questions/443859/s...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #bash #path
#avk47
ANSWER 1
Score 30
I would suggest dirname
and basename
:
for file in `find /my/path -name "*.ext"` do path="$(dirname "$file")" onlyfile="$(basename "$file")" # ... done
ACCEPTED ANSWER
Score 14
You can't. But you can do them separately.
$ foo=/usr/local/bin/bar
$ echo "${foo##*/}"
bar
$ echo "${foo%/*}"
/usr/local/bin