This is the part of the script I am using to rename the files returned by ls -A
:
for FILE in `ls -A`
do
ext=${FILE##*.}
NUM=$(($NUM+1))
NEWFILE=`echo $2_$NUM.$ext | sed 's/ /_/g'`
mv "$FILE" "$NEWFILE"
done
But can not find names with space! The $2 parameter can not be the cause of the error why I ever step a name without a space as a parameter, and this script takes that name and rename all files in the folder so to let them numbered and does not modify the file extension. Unfortunately it does not rename files with spaces in the name. Can someone help me?
$2_$NUM.$ext
. You're concatenating the variables with literals which will make the interpreter look for the variables$2_
and$NUM.
– Hugo Buff Mar 14 '14 at 12:04ls
command shouldn't be parsed ever! – Radu Rădeanu Mar 14 '14 at 13:27