#!/bin/bash

## Mueve todos los elementos de la carpeta donde se ejecuta a subcarpetas
## basado en la primera letra de cada elemento

shopt -s nocasematch
shopt -s nocaseglob

readonly letters="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
readonly numbers="0 1 2 3 4 5 6 7 8 9"

for i in $letters; do
  mkdir -p "$i"
  for element in "$i"*; do
    if [ "$element" != "$0" ] && [ "$element" != "$i" ]; then
      mv -v "$element" "$i"
    fi
  done
done

for i in $numbers; do
  mkdir -p "0-9"
  for element in "$i"*; do
    if [ "$element" != "$0" ] && [ "$element" != "$i" ]; then
      mv -v "$element" "0-9"
    fi
  done
done