I want to get just the name of the parent directory for a file.
Example: When I have
path=/a/b/c/d/file, I want only
d and not
/a/b/c/d (which I get from
dirname $path) as output.
Is there any sophisticated way to do this?
It sounds like you want the basename of the dirname:
You can use pwd to get the current working directory, and use parameter expansion to avoid forking it into another (sub)shell.
Edit: proven source
I think this is a less-resource solution:
edit: Sorry, nested expansion isn't possible in bash, but it works in zsh. Bash-version: