Vineeta wrote:
> Hi,
> I am trying to figure out what's wrong in the script that i have written?
> I am trying to copy the file to another location when the user says "y" to the
> interactive mode of rm i.e.
> rm -i
>
> If y,copy to another location
> else exit.
>
> Here's the code again:
> #!/bin/bash
> echo 'Rm script follows..'
> rm -i $1
> if [ "$?" = "0" ]
> then
> cp $HOME/$1 ./trashdir
> else
> exit 1
> fi
>
Looks to me like you are deleting the file first and when you get around to
the copy the file is already gone.
try putting the rm -i $1 at the end or swap the rm an cp commands. You will
need to emulate the rm prompt for the user
how bout somethinglike
#!/bin/sh
if [ -f $1 ];then
echo -n "rm: remove \'$1\'?"
read response
echo "response was : $response"
if [ $response = "y" -o $response = "Y" ];then
cp $1 ./trashdir/
rm -f $1
echo file has been deleted
fi
else
echo "$1 not a regular file"
fi
Should work but needs a little work. the error condition of no trashdir
existing is not taken care of. I removed the HOME but if that is what
you had in mind then of course put it back.
HTH
Bret
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list