[plug] Slightly OT - program that will append a random number file names

Russell Steicke russellsteicke at gmail.com
Thu Oct 1 23:05:34 WST 2009


On Thu, Oct 1, 2009 at 8:35 PM, sothisistheinternet
<sothisistheinternet at gmail.com> wrote:
> Hi all,
>
> I have an mp3 player that can't do shuffle play. Is there a program
> that I could use to append a random number, 1-10 say, to the
> beginnings of file names so that when I transfer them to the mp3
> player it works sorta like a shuffle play feature? Prefer command line
> and rpm, but I'll take anything.

Lots of random numbers:

#!/bin/bash
while : ; do echo $RANDOM ; done

Range limiting the random numbers, 0 to 9:

#!/bin/bash
while : ; do echo $(($RANDOM % 10)) ; done

^C will stop any of these.  You may have to press ^C more than once.

Now, to prepend the numbers to file names:

#!/bin/bash
for filename in "$@" ; do
  echo $((RANDOM%10))-"$filename"
done

Put that in a file.  chmod +x.  Run it with the names of the mp3 files.

$ ./f.sh a.mp3 b.mp3 "a file name with spaces.mp3"
5-a.mp3
9-b.mp3
2-a file name with spaces.mp3
$


-- 
Virus found in this message.



More information about the plug mailing list