The solution @jherran supplied should probably meet you needs. If you just want the script to give you the next filename, rather than create it for you, change "touch" to "echo" at the end of his script.
However, this will get slower and slower as you add many files. If you have a need for sequential numbers, you could just write the current number out to a file, then read it back in before writing your next file, write out the new number, and write out your file. I've provided sample code to do that below.
However, if you don't need sequential numbers, and just want non-colliding filenames, date-stamps are pretty useful. They sort as you'd expect, and if you don't time-travel, are monotonically increasing.
For an answer to to the question you asked (shell script to return the next value) based on my suggestion above of just using a counter file, here is this:
#!/usr/bin/sh
if [ -f counter.txt ]; then
{
VAL=`cat counter.txt`
echo "out-$VAL.avi"
VAL=`expr $VAL + 1`
echo "$VAL" > counter.txt
exit 0
}
fi
echo "out-1.avi"
echo "2" > counter.txt
exit 0
Or, if you want to go with my suggestion of date-stamps for uniqueness and sorting, just have your file writing program grab the output of this command:
date +%F-%T
or whatever granularity of dates and times you find useful. The above will give you something like this:
2014-12-01-16:41:33
Slap a ".avi" on the end and you have timestamped filenames, down to the second.