diff --git a/trm.sh b/trm.sh index 8b91763..cbbb664 100755 --- a/trm.sh +++ b/trm.sh @@ -28,7 +28,6 @@ echo " -t test mode, just show what would be done" echo " -v verbose mode - noisy output" echo " -x execute, overrides previous -t" - } @@ -110,7 +109,11 @@ done # Notify if in test mode - echo ${TESTMODE} + + if [ -n "${TESTMODE}" ] + then + echo ${TESTMODE} + fi # Process arguments @@ -119,10 +122,12 @@ do # Symlinks require special care + if [ -L "$1" ] then # Bare symlink itelf + REALPATH=$(readlink -f $(dirname "$1")) if [ "${REALPATH}" = '/' ] then @@ -132,17 +137,21 @@ REALPATH="${REALPATH}"/$(basename "$1") # Process normal files and directories + else REALPATH=$(readlink -f "$1") fi # See if we want serial numbers + SERIAL="" if [ -n "${SERIALNO}" ] then SERIAL=".$(date +%Y%m%d%H%M%S)" fi + # Figure out absolute paths for source and destination + SRCDIR=$(dirname "${REALPATH}") if [ "${SRCDIR}" = '/' ] then @@ -152,14 +161,20 @@ SRCFIL=$(basename "${REALPATH}") DESDIR="${GRAVEYARD}${SRCDIR}" DESFIL="${SRCFIL}${SERIAL}" - CMD="${OPERATOR} $VERBOSE '${REALPATH}' '${DESDIR}/${DESFIL}'" + + # If we're in test mode, just show what we would do + if [ -n "${TESTMODE}" ] then echo ${CMD} + + # We're really doing this + else # Handle interactive requests + if [ -n "${INTERACTIVE}" ] then echo -n "${INTERPROMPT} ${REALPATH}? " @@ -173,6 +188,8 @@ fi + # Make sure the destination directory exists and do the work + mkdir -p "${DESDIR}" eval ${CMD} fi @@ -184,8 +201,10 @@ } +##### # Run now if invoked directly on the command line. (Otherwise, we're # just loading the function above into the current shell context.) +##### if [ $(basename "$0") = "trm.sh" ] then