#!/bin/bash # version: 0.3.6-r8 FILE=$1 DIR=$(dirname ${FILE}) FILENAME=$(basename ${FILE}) # check if there are already protected file # set counter to HIGHEST FILE +1 for oldpretected in $(find ${DIR} -iname "._cfg????_${FILENAME}" | sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | sort -t'%' -k3 -k2 | cut -f1 -d'%') do COUNTER=$(echo ${oldpretected}|cut -d_ -f2|sed -e "s:cfg::") done #if counter is zero than set to 0001 else to ${COUNTER}+1 if [ -z "${COUNTER}" ] then COUNTER=0001 else #set COUNTER +1 #this is a tricky one: #exp COUNTER may be 0901 # exp ${COUNTER} + 1 is 902 NOT 0902 COUNTER=${COUNTER/$(expr ${COUNTER} + 0)/$(expr ${COUNTER} + 0001)} fi echo ${COUNTER}