I need a script that will create a file with the next file in a sequence. Each execution of the script should only create one file and the script could be run zero or more times on any given day. The files should be named after the current date in format %y%m%d with the second file having -01 appended, the third file to be created on a given date would have -02 etc. For example:20170125.txt  // first file create on the day.20170125-01.txt // 2nd file20170125-02.txt // 3rd fileSo far I've got this super basic script that creates my first daily file but I'm stumped as to how to do the incremental numbering after that.#! /bin/bashDATE=`date +%Y%m%d`touch $DATE.txt
How do I create sequentially numbered file names in bash?
bash;shell script;scripting
today=$( date +%Y%m%d )number=0while test -e $today$suffix.txt; do    (( ++number ))    suffix=$( printf -- '-%02d' $number )donefname=$today$suffix.txtprintf 'Will use %s as filename\n' $fnametouch $fnametoday gets today's date, and we initialize our counter, number to zero. Then we test to see if the filename already exists ($suffix will be empty to start with).  If it does, increment the counter and create a new suffix using printf. Repeat until we no longer have a filename collision.The format string for the printf, -%02d, means a literal dash followed by a zero-filled two-digit integer. The double dash (--) are needed in front of the format string to stop printf from interpreting the dash in the format string as an option.The touch is just there for testing.This will generate filenames like20170125.txt20170125-01.txt20170125-02.txt20170125-03.txtetc. on subsequent runs.