#!/bin/bash # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/writeprotected,v 1.8 2005-06-01 15:47:06 niro Exp $ 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)} # the same without need of expr COUNTER=${COUNTER/$((${COUNTER} + 0))/$((${COUNTER} + 0001))} fi echo ${COUNTER}