Sponsored Content
Full Discussion: Help with this please
Top Forums UNIX for Dummies Questions & Answers Help with this please Post 302128163 by cfajohnson on Monday 23rd of July 2007 05:01:57 AM
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.
 
CGI::Pretty(3pm)					 Perl Programmers Reference Guide					  CGI::Pretty(3pm)

NAME
CGI::Pretty - module to produce nicely formatted HTML code SYNOPSIS
use CGI::Pretty qw( :html3 ); # Print a table with a single data element print table( TR( td( "foo" ) ) ); DESCRIPTION
CGI::Pretty is a module that derives from CGI. It's sole function is to allow users of CGI to output nicely formatted HTML code. When using the CGI module, the following code: print table( TR( td( "foo" ) ) ); produces the following output: <TABLE><TR><TD>foo</TD></TR></TABLE> If a user were to create a table consisting of many rows and many columns, the resultant HTML code would be quite difficult to read since it has no carriage returns or indentation. CGI::Pretty fixes this problem. What it does is add a carriage return and indentation to the HTML code so that one can easily read it. print table( TR( td( "foo" ) ) ); now produces the following output: <TABLE> <TR> <TD> foo </TD> </TR> </TABLE> Tags that won't be formatted The <A> and <PRE> tags are not formatted. If these tags were formatted, the user would see the extra indentation on the web browser caus- ing the page to look different than what would be expected. If you wish to add more tags to the list of tags that are not to be touched, push them onto the @AS_IS array: push @CGI::Pretty::AS_IS,qw(CODE XMP); Customizing the Indenting If you wish to have your own personal style of indenting, you can change the $INDENT variable: $CGI::Pretty::INDENT = " "; would cause the indents to be two tabs. Similarly, if you wish to have more space between lines, you may change the $LINEBREAK variable: $CGI::Pretty::LINEBREAK = " "; would create two carriage returns between lines. If you decide you want to use the regular CGI indenting, you can easily do the following: $CGI::Pretty::INDENT = $CGI::Pretty::LINEBREAK = ""; BUGS
This section intentionally left blank. AUTHOR
Brian Paulsen <Brian@ThePaulsens.com>, with minor modifications by Lincoln Stein <lstein@cshl.org> for incorporation into the CGI.pm dis- tribution. Copyright 1999, Brian Paulsen. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Bug reports and comments to Brian@ThePaulsens.com. You can also write to lstein@cshl.org, but this code looks pretty hairy to me and I'm not sure I understand it! SEE ALSO
CGI perl v5.8.0 2002-06-01 CGI::Pretty(3pm)
All times are GMT -4. The time now is 05:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy