for i in *.txt
do
#Text files
echo $i
#checking for existing files
if [ -f ~/txt/$i ]
then
j=1
#Stripping .txt from the files
temp=${i%".txt"}
#appending filaname with counter "($j)"
i=$temp($j).txt
#move to folder /txt
mv $i ~/txt
else
mv $i ~/txt
fi
done
My loop checks a folder for an existing file, if that file name exists, the file name is appended (ex (1), (2) etc.
Once the file name has been renamed and it is held in $i
I try to mv it but I'm getting:
mv: cannot stat 'list(1).txt': No such file or directory
I tried mv {$i} ~/txt
, mv [$i] ~/txt
etc...no luck. Any ideas?