Este script é baseado na sua resposta, mas usa find
em vez de passar pelo sistema de arquivos manualmente.
#!/bin/bash
unrar_if_needed()(
file=""
dir="$(dirname "$file")" # Extract dir name from file path.
echo "Found: $file"
if [[ -f "$file".processed ]]; then # Double brackets are better.
echo " Already unrared."
else
echo -n " Unraring... "
if unrar -inul e "$file" "$dir"; then # This if-statement is not necessary, but a nice touch.
touch "$file".processed
echo "Done."
fi
fi
)
export -f unrar_if_needed
if [[ "" ]]; then
dir=""
else
dir=.
fi
echo "Looking in: $dir"
find "$dir" -iname "*.rar" -exec bash -c 'unrar_if_needed {}' \; # find runs the custom function.
A saída deve ficar assim:
$ script.sh somedir
Looking in: somedir
Found: ./somedir/file1.rar
Unraring... Done.
Found: ./somedir/file2.rar
Already unrared.