Michael C. Toren on 22 Feb 2006 14:58:35 -0000


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

Re: [PLUG] bash script help needed


On Wed, Feb 22, 2006 at 09:39:56AM -0500, Art Alexion wrote:
> 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

Try replacing your "mv" line with:

	mv -i "$OLD" "$NEW"

Despite the fact that you are removing spaces, it sounds like there are
other whitespace characters present in the filenames you're attempting to
rename, which when passed unquoted on the command line are being parsed
as multiple command line argument.  The "-i" switch places "mv" in
"interactive mode", meaning it will prompt you before blindly overwriting
a destination filename which already exists -- handy for scripts such as
your which will be automatically renaming files.

To weed out additional whitespace characters, try changing your "sed"
line to:

	NEW=`echo $OLD | sed 's/[[:space:]]/_/g' | tr [:upper:] [:lower:]`

which will catch both spaces, tabs, and newlines.

See also the "rename" command, which comes with perl.

HTH,
-mct
___________________________________________________________________________
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