 <p>Use 2 variables. First variable will store the last execution date and the next one will store the version. Whenever you execute the script, first check if the date is same. If yes, increment the version else set the version to 1. Export the variables so that they retain their values.</p> <pre><code>if [ "`date +'%Y%m%d'`" == "$LAST_EXEC_DATE" ]; then (( VERSION += 1 )) else VERSION=1 LAST_EXEC_DATE=`date +"%Y%m%d"` fi export LAST_EXEC_DATE export VERSION </code></pre>