Help with this please


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with this please
# 1  
Old 07-20-2007
Data Help with this please

Folks;
Can any one tell me what these commands below do:


user=$(/usr/ucb/whoami)

DZERO=${0}
PROG=$(basename ${DZERO})
while [ -h ${DZERO} ]; do
DZERO=$(ls -l ${DZERO} | awk '{print $NF}') done PDIR=$(dirname ${DZERO}) if [ ${PDIR} = '.' ]; then
PDIR=${PWD}
elif [ $(expr ${PDIR} : "\(.\).*") != '/' ]; then
PDIR=${PWD}/${PDIR}
fi

Smilie
# 2  
Old 07-23-2007
Quote:
Originally Posted by moe2266
Folks;
Can any one tell me what these commands below do:

user=$(/usr/ucb/whoami)

Store the output of whoami in the variable user.
Quote:
DZERO=${0}

Store the script name in DZERO (this is unreliable).
Quote:
PROG=$(basename ${DZERO})

Extract the filename from $DZERO and store it in PROG. The more efficient method is:
Code:
PROG=${DZERO##*/}

Quote:
while [ -h ${DZERO} ]; do
DZERO=$(ls -l ${DZERO} | awk '{print $NF}')
done

If the file in $DZERO is a symbolic link, find the file to which it is linked. (Not the best way to do that.)

Quote:
PDIR=$(dirname ${DZERO})

Store the directory containing the command in PDIR. The more efficient method is:

Code:
case $DZERO in
   *.*) PDIR=${DZERO%/*} ;;
   *) PDIR=. ;;
esac

Quote:
if [ ${PDIR} = '.' ]; then
PDIR=${PWD}
elif [ $(expr ${PDIR} : "\(.\).*") != '/' ]; then
PDIR=${PWD}/${PDIR}
fi

A very inefficient way of doing:

Code:
case $PDIR in
   .) PDIR=$PWD ;;
   /*) PDIR=$PWD/$PDIR ;;
esac

That is, getting the full path to the script's directory into PDIR.

The script is trying to do something that cannot be done reliably, and that is usually tring to solve the wrong problem. It is doing it badly, both in terms of the methods used and the code that implements those methods.
# 3  
Old 07-23-2007
Thanks a lot for the help Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question