There must be a lot more straightforward way of doing this, but I failed to find it. Therefore I (re)invented a method of determining the parent directory from Bash:
#!/bin/sh
if [ x"$1" != x"" ]
then
readlink -f $1 | tr '/' ' ' | gawk '
{
for (v=1;v < NF;v++)
printf("/%s",$v)
printf("\n")
}'
fi
As I mentioned there must be an easier way… Anyway, I have this script a file called ‘parentname’.
dirname $( pwd ) | tr / \\n | tail -1
By: D W on July 16, 2009
at 10:33 am