B0rderLine
Technical User
Hi first timer here...Can anyone help with script below. Seems to work okay, but problem arises if user enters full path of file .. mv will not work.
Apparently I have to use awk or something to determime path component of $1
#! /bin/sh
# Prog that moves file specified by user
# File is moved to "trash" folder where it can be
# recovered from if required# To use for adding removed file
# details to tra.db
TRASH="${HOME}/trash"
if [ $# -ne 1 ]
then
echo "name of file: \c"
read fname
if [ -z "$fname" ]
then
echo " $No file ... Quitting.... "
exit 1
else
echo "checking $fname"
fi
else
fname="$1"
fi
fPID="$fname$$"
# Check file
if [ -f $fname -a -w $fname ]
then
echo " Preparing to remove"
else
echo " No file: $fname "
echo " Check permission and file exists"
exit 1
fi
if [ ! -d $TRASH] # Check "trash" exists
then
mkdir $TRASH
fi
if mv -i $fname ${TRASH}/${fPID}
then
echo "moved file: $fname"
echo ${fname}\ $fPID >> ${HOME}/tra.db
exit 0
else
echo "Error: Can not mv $fname .. Exit and try again"
exit 2
fi
Apparently I have to use awk or something to determime path component of $1
#! /bin/sh
# Prog that moves file specified by user
# File is moved to "trash" folder where it can be
# recovered from if required# To use for adding removed file
# details to tra.db
TRASH="${HOME}/trash"
if [ $# -ne 1 ]
then
echo "name of file: \c"
read fname
if [ -z "$fname" ]
then
echo " $No file ... Quitting.... "
exit 1
else
echo "checking $fname"
fi
else
fname="$1"
fi
fPID="$fname$$"
# Check file
if [ -f $fname -a -w $fname ]
then
echo " Preparing to remove"
else
echo " No file: $fname "
echo " Check permission and file exists"
exit 1
fi
if [ ! -d $TRASH] # Check "trash" exists
then
mkdir $TRASH
fi
if mv -i $fname ${TRASH}/${fPID}
then
echo "moved file: $fname"
echo ${fname}\ $fPID >> ${HOME}/tra.db
exit 0
else
echo "Error: Can not mv $fname .. Exit and try again"
exit 2
fi