rename appears useless in Ubuntu

Heike C. Zimmerer nospam08q2 at gmx.net
Wed May 13 09:05:06 UTC 2009


anthony baldwin <baldwinlinguas at gmail.com> writes:

Some comments:
> #!/bin/bash
>
> # nospace
> # replace spaces with underscores
>
> echo "What kind of files do you wish to rename.  Please enter the file 
> extension:"
>
> read a
>
> for i in $(ls -1 *$a)

You don't use your variable i anywhere later.  The whole loop is
pointless.  It would not even work if the variable i were used, since
$(ls -1 $a) splits the string at every white space, you won't get
filenames containing spaces through it.  A working version would be

  for i in *."$a"

Now:

> do
> rename \  _ *.$a

With the for clause adjusted as depicted above, use

  mv "$i" "${i// /_}"

here, and you should be done (not tested).  As you wrote it, the rename
command is called many times with the first call doing the real work and
getting all the file names as arguments (*.$a), and the remaining calls
being useless (but doing no harm) since there a no spaces in file names
any more.


> done


Heike





More information about the ubuntu-users mailing list