John Ashmead on 22 Feb 2006 15:27:36 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] bash script help needed


There are still spaces in "$OLD", so it is being expanded as a two (or more) part name. You need something like:

mv "$OLD" "$NEW"


On Feb 22, 2006, at 9:39 AM, Art Alexion wrote:

I am trying to iron out a script that renames all files in a current
directory to replace embedded spaces with underscores, and makes
everything lower case.

The suggestion that I was given was (in pertinent part):

for OLD in *
  do
    NEW=`echo $OLD|sed s/\ /\_/g | tr [:upper:] [:lower:]`
    echo "OLD=\"$OLD\""
    echo "NEW=\"$NEW\""
    echo -e "mv \"$OLD\" \"$NEW\"\n"
  done

But while the messages sent to the console indicated what I wanted to do
was happening, and there were no errors reported, no changes were
actually being made to the filenames.


I read the echo man page and it seemed that the line

echo -e "mv \"$OLD\" \"$NEW\"\n"

didn't actually execute the mv command, so I added the line

mv $OLD $NEW

after it, so it now reads

for OLD in *
  do
    NEW=`echo $OLD|sed s/\ /\_/g | tr [:upper:] [:lower:]`
    echo "OLD=\"$OLD\""
    echo "NEW=\"$NEW\""
    echo -e "mv \"$OLD\" \"$NEW\"\n"
    mv $OLD $NEW
  done

But this results in the error

mv: when moving multiple files, last argument must be a directory

even though $NEW does not yet exist, so I am not really moving multiple
files.


What am I doing wrong?

--

_______________________________________
Art Alexion
Arthur S. Alexion LLC

PGP fingerprint: 52A4 B10C AA73 096F A661 92D2 3B65 8EAC ACC5 BA7A
The attachment -- signature.asc -- is my electronic signature; no need for alarm.
Info @ http://mysite.verizon.net/art.alexion/encryption/ signature.asc.what.html


Key for signed PDFs available at
http://mysite.verizon.net/art.alexion/encryption/ArthurSAlexion.p7c
The validation string is TTJY-ZILJ-BJJG.
________________________________________

______________________________________________________________________ _____
Philadelphia Linux Users Group -- http:// www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug- announce
General Discussion -- http://lists.phillylinux.org/mailman/ listinfo/plug



John Ashmead Ashmead Software & Consulting, Inc. 139 Montrose Avenue Rosemont, PA 19010-1508 (610) 527 9560 fax (610) 527 4640 john.ashmead@ashmeadsoftware.com http://www.ashmeadsoftware.com/


___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug