-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_list.sh
executable file
·57 lines (41 loc) · 1 KB
/
random_list.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#
# Random Music List
#
# Author: Pablo M.
# Email: [email protected]
#
# Version: 0.5
###########################################################
# Calculamos el numero de ficheros
i=0
for file in *.mp3; do
((i++))
done
range=$i
# Iniciamos el contador
# Generamos el primer numero aleatorio
# Iniciamos el array
j=0
number="$((($RANDOM % $range) + 1))"
declare -a narr
# Hacemos un bucle en el que almacenamos los numeros aleatorios
# generados en el array. Comprobamos que no esten repetidos
# y añadimos el numero generado al principio del nombre del fihero
for file in *.mp3; do
narr[$j]=$number
mv "$file" "$number-$file"
# Comprobacion de que este repetido el numero
while [[ ${narr[*]} =~ $number ]]; do
number="$(($RANDOM % $range))"
# Paramos el bucle en caso de haber llegado el limite
if [[ ${#narr[@]} == $range ]]; then
break
fi
done
((j++))
done
# Vemos el contenido del array
#echo ${narr[*]}
# Comprobar longitud del array
#echo ${#narr[@]}