#!/bin/bash E_ERR_ARG=65 if (( "$#" < 1 )) then echo "----------------------------------------" echo "Utilizzo: `basename $0` [-r] collezione " echo " -r genera una playlist casuale" echo "----------------------------------------" exit $E_ERR_ARG elif (( "$#" == 2 )) then path="$2" else path="$1" fi echo if [ ! -d "$path" ] && [ ! -w "$path" ] then echo "Controlla il percorso" exit $E_ERR_ARG fi path=${path%/} echo "Cerco i file.mp3 in \"$path/\" ricorsivamente" find -P "$path" -name *.mp3 > "$path"/playlist echo "Scrivo i file.mp3 in \"$path/playlist\"" echo "end" >> "$path"/playlist if [ "$1" == "-r" ] then echo "Randomizzo la playlist" exec < "$path"/playlist read song number=1 while [ "$song" != "end" ] do array[$number]=$song read song let "number++" done count=1 if [ -e "$path"/rand_list ]; then rm "$path"/rand_list; fi touch "$path"/rand_list while [ "$count" -le "$number" ] do let "numero = $RANDOM % $number+1" if [ casual[$numero] != 1 ] then echo ${array[$numero]} >> "$path"/rand_list casual[$numero]=1 let "count+=1" fi done echo; echo echo "---------------------------------------------------------------------------------------" echo "Playlist casuale presente in \"$path/rand_list (/playlist per la lista ordinata)\"" echo "---------------------------------------------------------------------------------------" echo else echo; echo echo "-------------------------------------" echo "Playlist presente in \"$path/playlist\"" echo "-------------------------------------" echo fi exit 0