Ho uno script che mi sta dando dei problemi, so che devo rifarlo in modo ricorsivo ma sto avendo qualche problema. Lo script dovrebbe rinominare tutti i file e le cartelle in una determinata cartella rimuovendo caratteri speciali come $ -,) (! E sostituendo "" con "_"
Ecco il pezzo che devo rifare:
# Rename directories
find "$ORIG_DIR" -name "*" -type d| while read dname
do
NEW_DIR='echo "$dname" |sed -E 's/^[ \t]*//g; s/[ \t]*$//g; s/\./_/g; s/\,/_/g; s/ /_/g''
# Rename files
find "$ORIG_DIR" -name "*" -type f | while read fname
do
NEW_FNAME='echo "$fname" |sed -E 's/^[ \t]*//g; s/[ \t]*$//g; s/\./_/g; s/(.*)_/\./; s/\,/_/g; s/ /_/g''
if [ -e $NEW_FNAME ]
then
echo "$NEW_FNAME already exists. Not replacing $fname"
else
echo "Replacing $fname with $NEW_FNAME"
mv "$fname" $NEW_FNAME
fi
done
if [ -e $NEW_DIR ]
then
echo "$NEW_DIR already exists. Not replacing $dname"
else
echo "Replacing $dname with $NEW_DIR"
mv "$dname" $NEW_DIR
fi
done
END