On Wednesday 02 February 2005 16:06, Rikard Johnels wrote:
I want to create folders according to the standard; "dd-mm-yyyy-xx" where "dd" is day, "mm" is month, "yyyy" is year and xx is a running number. If one folder "-01" exists the script checks for "-02" etc.
Hi Rikard, I'm using a bash function to create backups of files with a target naming convention similar to what you are looking for. You might be able to build your own function based on it. Code is attached. Michael <bash_function> function mb { if [ -z "$*" ]; then echo "Usage: $0 <filename_1> <filename_2> ..." echo "Creates copy of <filename> as <filename>.YYYYMMDDxx" return fi local maxvers=99 local file local ext=$(date +"%Y%m%d") local i local copy local copystat for file in "$@"; do if [ ! -r "$file" ]; then echo "File "$file" is not readable" break fi i=1 copystat=999 while [ $i -le $maxvers ]; do copy=$(printf "%s.%s%02d" $file $ext $i) if [ ! -e "$copy" ]; then echo "Creating backup $copy" cp -p $file $copy copystat=$? break fi ((i=i+1)) done if [ $copystat -ne 0 -a $i -gt $maxvers ]; then echo "Error: too many backups of $file already exist" elif [ $copystat -ne 0 ]; then echo "Error: could not create backup of $file" fi done } </bash_function>