Add to Google Reader or Homepage |
~ pjvenda / blog
$home . blog . photography

21 April 2011

code snippet and a quote

Code snippet unrelated to quote and quote unrelated to code snippet.

Code snippet [needed this for a while]:

#!/bin/bash

function fsuffix() {
       local LEN=2
       # ${1} full path
       FILE=$(basename ${1})
       DIR=$(dirname ${1})

       # get last file of the specified type
       LS=$(ls -1 "${1}"-* 2>/dev/null| egrep "${1}-[0-9]+$" | sort -nr | head -n 1)

       if [ -z "${LS}" ]; then
               FSTSUF=1
               LSTSUF=0
               LST=""
               LSTSFX_OUT=""
       else
               LSTSUF=$(echo ${LS} | egrep -o "[0-9]*$")
               FSTSUF=$((LSTSUF+1))
               printf -v LST "%s-%0${LEN}d" "${FILE}" "${LSTSUF}"
               LSTSFX_OUT="${DIR}/${LST}"
       fi

       printf -v FST "%s-%0${LEN}d" "${FILE}" "${FSTSUF}"

       FSTSFX_OUT="${DIR}/${FST}"
       return ${FSTSUF}
}

Quote:
I'm going to record this in your file, under commendations-oh, there's a lot of space here. "Did well...enough"

No comments: