dirname directorywill return the path of the current directory from the beginning of the directory name to the last ``/".
For example,
dirname /usr/people/cantinwill return /usr/people. But
dirname cantinwill return . (dot).
For example, the following script will take as its first parameter, the name of a directory, and return its absolute path name. The directory must be given either as a relative or absolute path name.
#!/bin/sh
# Returns full path name of a directory.
if [ $# -ne 1 ]
then
echo " "
echo " $0: must have one parameter."
echo " "
exit
fi
C_DIR=`pwd`
if test "`dirname $1`" = "."
then
FULL_NAME=$C_DIR/$1
else
FULL_NAME=$1
fi
echo "Absolute path name is $FULL_NAME."