On Tue, Mar 14, 2006 at 07:20:30AM -0600, Jordan Peacock wrote:
>       mkdir `basename $i .tar`.dir   # making a new directory, with $i
> being all characters before .tar. What is the significance of basename

The file name consists of a "base name" and an extension.  `basename
<file name> <extension>` strips the given extension from the end of the
file name and returns... the base name.

> or the single quotes?

First off, note that they're ` (what I call a backtick, normally on
the ~ key on US keyboards), not ' (a single quote/apostrophe,
normally sharing a key with ").  It looks like you've probably got it
right, but just making sure since switching between the two would
definitely cause problems!

Anyhow, enclosing something in backticks tells bash to execute the
command within them and substitute its output for the backtick-
enclosed string.

> Does .dir change it's 'extension' to a
> directory?

Nope, it doesn't change anything - the original command is mkdir, not
mv.

The total effect of this line is to create a new directory with the
same name as the tar file, but with the extension .dir instead of
.tar.  Assuming $i is tarfile.tar, `basename $i.tar` returns
"tarfile", giving you the command "mkdir tarfile.dir".

>       cd `basename $i .tar`.dir  # we're moving into the newly made
> directory, although i'm not sure why the .tar stuff is still there;
> it's a directory now, right?

Correct that it moves into the newly-created directory, but the
original tarfile has not been touched beyond looking at its name.  It
has not been changed in any way.  The `basename $i .tar` is repeated
because the name of the directory wasn't stored, so we have to
generate the name again.  If you didn't want to run basename twice,
you could instead do:

$dirname=`basename $i .tar`.dir
mkdir $dirname
cd $dirname

>       tar xvf ../$i   # we execute tar and look for the file $i in the
> parent directory
>       cd .. # moving back into the parent dir for the next file
>       ;; # denotes end of case

Yep, yep, and yep.

> I'm experiencing some errors at the cli as well;
> 
> line 18: unexpected EOF while looking for matching ``'
>       cd `basename $i .zip`.dir # this is the trouble line

What's the value of $i when you get this error?  My first guess would
be that it contains some characters which are significant to bash,
in which case you could try

cd `basename "$i" .zip`.dir

instead to provide some protection against that.  (Personally, I'd put
the double quotes around $i anyhow, since so many people put spaces in
filenames these days, which is sufficient to break it if you don't
have the them.)

> line 25: syntax error: unexpected end of file # there is no line 25 ?
> The code ends at 24.

Well, if it's continuing to look for a stray ` after the final line
of the file, I'd say that counts as an "unexpected end of file", no?

-- 
The freedoms that we enjoy presently are the most important victories of the
White Hats over the past several millennia, and it is vitally important that
we don't give them up now, only because we are frightened.
  - Eolake Stobblehouse (http://stobblehouse.com/text/battle.html)