You are not logged in.
Hi!
I know this is easy with sed, but I could have sworn there once was a bash tool - maybe even coreutils - that's sole purpose was making strings like
"/folder/something/file.ex"
into
"/folder/something/"
or
"file.ex"
Am I mistaken or can someone tell me the name of this tool and if it's (still) common?
Thx!
Last edited by whoops (2011-01-04 12:36:09)
Offline
basename? That prints the folder.
You can do this using bash string substitution too.
Offline
To answer your other question, the command "dirname". Watch out for the root directory though. Both basename and dirname are owned by coreutils.
Offline
Exactly, thanks!
So simple, yet so hard to google.
Last edited by whoops (2011-01-04 12:36:53)
Offline
You can use bash with parameter expansion:
foo="/folder/something/file.ex" ; echo "${foo##*/}" ; echo "${foo%/*}"
Offline