Mixed Case Directory Names

Rejean Proulx rejean at interfree.ca
Mon Nov 10 23:03:07 EST 2003


i tried it and it didn't change directories.  In fact, it did nothing.  It
is as if it doesn't read the $1 as a variable.  I commented out the last rm
to make sure it didn't do anything and in fact there is not renamer$$ in
/var/tmp

The script must be ok because there is no error.  It just does nothing.  if
I just enter renamer.sh with no parameters it does nothing.  I thoght it
should say invalid directory or something.

#!/bin/sh
cd $1 || echo "No such directory." && exit 1;
tf=/tmp/renamer.$$;
rm -f $tf;
ls *[A-Z]* | awk '{print "mv", $1, tolower($1)}' > $tf;
source $tf;
rm -f $tf;
exit 0;

 Rejean Proulx
Visit my family at http://interfree.ca
MSN is: rejp at rogers.com
Ham License VA3REJ

----- Original Message ----- 
From: "Luke Davis" <ldavis at shellworld.net>
To: <Speakup at braille.uwo.ca>
Sent: Monday, November 10, 2003 10:27 PM
Subject: Re: Mixed Case Directory Names


> One of the first things the script does, is to place the name of a file in
> the "tf" variable.
> That file name is "/tmp/renamer.", followed by the current unique process
> ID (a number from 1 to five digits).
>
> ls *[A-Z]*
>
> Is a standard ls, with the file spec provided as a (bastardized
> (bashtardized?))  regular expression.  That regexp says:
>
> *: zero or more characters of any kind
> [: start a character class specification
> A-Z: class specification: any characters inclusively between capital A and
>      capital Z (that is: the entire capitalized alphabet)
> ]: Close the class spec
> *: any character
>
> So, ls will only list files that have at least one capital letter in their
> names.  Otherwise, there would have had to been some error handling which
> I did not care to deal with.
>
> Now, we send the output of that ls, via the pipe character (send to
> another program) ("|"), into the awk program, which is a text processor.
> That program takes each line of input (a single file name--ls outputs
> files one per line when sending to programs), and does the following with
> it:
>
> 1.  Outputs the letters "mv".
> 2.  Outputs a space.
> 3.  Outputs the first field of the line (the file name).
> 4.  Outputs a space.
> 5A. Runs the "tolower" function, giving it that same first field as the
>     string to convert to lower case.
> 5B. Outputs the result of that function, which is a lower case file name.
>
> It does that for each line, and sends the output to the file named in the
> variable "tf" (see the top of the script).
> It then sources that same file from $tf.  By sourcing, I mean that it
> reads in the contents of that file, and executes them as if they were
> originally part of the program.
>
> There is also some business about deleting $tf if it already exists, and
> at the end of the program, changing to the initial directory (and
> generating an error if that doesn't work), and so on.
>
> If you want to see what the sourced file looks like, remove the last "rm"
> statement, then read a file in /tmp, called "renamer.<some numbers>".
>
>  HTH
>
> Luke
>
>
>
>
>
>
> On Mon, 10 Nov 2003, Rejean Proulx wrote:
>
> > Thanks, I trust you, but I'm making a copy of this stuff and then I'll
run
> > it.  Seriously, I wouldn't mind asking you questions about this script.
I
> > know that you are storing an ls of the files.  but I'm not quite sure
how
> > the rest of the thing works.
>
> _______________________________________________
> Speakup mailing list
> Speakup at braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup





More information about the Speakup mailing list