I have file getting generated (testfile) eachtime a script is run in working directory. I have to copy that generated file to a directory (testfolder) and have it incremented by a .ext
If the script is run for first time then copy the testfile to testfolder as "testfile.0" and when run second time copy the testfile to testfolder as "testfile.1" and so on.
My script:
#!/bin/sh
file="testfile"
n=1
ls folder/${file}* | while read i
do
if [ folder/${file}.${n} = ${i} ]
then
n=$(( $n + 1 ))
fi
done
cp testfile folder/${file}.${n}
this is only working for first increment "folder/testfile.0"