If you're going to invoke perl, you may as well do it all in Perl:
Code:
perl -MCwd=cwd -e 'print((split(m:/:, cwd))[-2]."\n")'
A somewhat more readable version:
Code:
perl -MCwd=cwd -e '@a = split(m:/:, cwd); print "$a[-2]\n"'
Otherwise, under bash, you could use something like:
Code:
basename `dirname "$PWD"`