fix to handle file/dir names with embedded spaces or leading dashes
1 parent 6ad50f8 commit 60eae93ce8b109a28d56325be4bedba32235c75e
@tundra tundra authored on 29 Oct 2016
Showing 1 changed file
View
18
trm.sh
 
COPYRIGHT='2016'
GITID='1ca95bc tundra Fri Oct 28 09:27:57 2016 -0500'
VERSION='1.102'
OLDIFS=${IFS} # Preserve IFS for later use in protecting files/dirs with spaces in their name
 
GRAVEYARD="${HOME}/.graveyard"
INTERPROMPT="Do You Want To Remove(Copy):"
TESTING="Test Mode ..."
then
 
# Bare symlink itelf
 
REALPATH=$(readlink -f $(dirname -- "$1"))
REALPATH=$(readlink -f -- $(dirname -- "$1"))
if [ "${REALPATH}" = '/' ]
then
REALPATH=""
fi
 
# Process normal files and directories
 
else
REALPATH=$(readlink -f "$1")
REALPATH=$(readlink -f -- "$1")
fi
 
# See if we want serial numbers
 
 
SRCFIL=$(basename -- "${REALPATH}")
DESDIR="${GRAVEYARD}${SRCDIR}"
DESFIL="${SRCFIL}${SERIAL}"
CMD="${OPERATOR} $VERBOSE '${REALPATH}' '${DESDIR}/${DESFIL}'"
 
# Temporarily assign field separator to a character never used in
# a filename. Needed to preserve spaces in file/dirnames
 
IFS='>'
CMD="${OPERATOR} $VERBOSE -- '${REALPATH}' '${DESDIR}/${DESFIL}'"
 
# If we're in test mode, just show what we would do
 
if [ -n "${TESTMODE}" ]
eval ${CMD}
fi
 
shift
IFS=${OLDIFS}
 
done
 
}