Verifique, faça o que você quer.
Primeira maneira:
#!/bin/bash
declare -A arr_map
arr_map=([AP]=Fruit [RS]=Sweet)
# Iterate through indexes of array
for keyword in "${!arr_map[@]}"; do
# Search files containing the "-$keyword" pattern in the name
# like "-RS" or "-AP". This pattern can be tuned to the better matching.
for filename in *-"$keyword"*; do
# if file exists and it is regular file
if [ -f "$filename" ]; then
destination=${arr_map["$keyword"]}/"$filename"
# Remove these echo commands, after checking resulting commands.
echo mkdir -p "$destination"
echo mv -iv "$filename" "$destination"
fi
done
done
Segunda via:
#!/bin/bash
declare -A arr_map
arr_map=([AP]=Fruit [RS]=Sweet)
# Iterate through all files at once
for i in *; do
# If the file is a regular and its name conforms to the pattern
if [[ -f "$i" && "$i" =~ [A-Za-z]+-[A-Z]+[0-9]+ ]]; then
# trim all characters before the dash: '-' from the beginning
keyword=${i#*-}
# trim all digits from the ending
keyword=${keyword%%[0-9]*}
# if the arr_map contains this keyword
if [[ ${arr_map["$keyword"]} != "" ]]; then
destination=${arr_map["$keyword"]}/$i
# Remove these echo commands, after checking resulting commands.
echo mkdir -p "$destination"
echo mv -iv "$i" "$destination"
fi
fi
done