Reputation: 37156
I'm trying to get a substring of my parent directory. What's annoying is that I have to do it using two commands when one should suffice:
curDir=`pwd`; echo ${curDir##*/};
When I try to combine the two into one I get an error:
echo ${`pwd`##*/}
-bash: ${`pwd`##/}: bad substitution
How can I avoid use of a temp here?
Upvotes: 2
Views: 242
Reputation: 19757
echo ${`pwd`##*/}
will result in a parameter expansion like
echo ${/home/yourdir##*/}
But you don't need command substitution in you case. Bash provides a builtin variable:
echo ${PWD##*/}
Upvotes: 3
Reputation: 28120
In this instance I would do:
basename `pwd`
In the general case there may not be an equivalent for basename
but you can use sed:
pwd | sed 's,.*/,,'
Upvotes: 1