Help with my recycle bin code


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with my recycle bin code
# 1  
Old 03-04-2011
Help with my recycle bin code

Hi~ I have a problem with my recycle bin code.
Code:
#!/bin/bash

	if test !-d ~/.recyclebin   #if recycle bin does not exists

	then

	mkdir ~/.recyclebin 	# then create recycle bin

	else

	mv $1 ~/.recyclebin		#else move the deleted file in the recycle bin

	fi

so when I execute this it will be like:

Code:
$ del filename

but I receive the error:

Code:
./del: test: !-d: unary operator expected

*I am not the root by the way...

Please help me thanks
# 2  
Old 03-04-2011
You don't have to call 'test this' all the time, any sane shell should have lots of operators built in. [ -d "~/.recyclebin" ] || mkdir "~/.recyclebin" sort of thing. See test operators for a table of them. A few of them might be peculiar to BASH, most'll work anywhere.

You can also use the -p option to mkdir to simplify that more. If the directory already exists it does nothing.

Code:
#!/bin/sh

mkdir -p ~/.recyclebin && mv "$1" ~/.recyclebin

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-04-2011
thanks~

it worked Smilie\
Thank you!
# 4  
Old 03-04-2011
can you also help me with this?

I am creating a simple script that can "recover" a deleted file.

I already created a working del command wherein when I type
Code:
$ del filename

, the filename will be moved to a directory called recyclebin.

Now, in order for me to recover this file, I need to search for the filename inside the recyclebin and move it to the destination that the user will specify.



Code:
#!bin/bash
dest=$2

if [ !-d $dest ]

        echo "Error: The path $2 does not exists"

        else
                continue

                notFound=`find ~/.recyclebin -name $1`

                if [ $notFound != "false" ]

                        fname=$1

                        cp $fname $dest/${fname}1

                fi
fi

unfortunately the code does not work Smilie

What is wrong with my code?

I just want the script to be executed something like this:

Code:
 $ rcvr filename ~/destination

Please help me, thank you.
# 5  
Old 03-05-2011
For future reference, "doesn't work" isn't a good description. That has meant anything from "too slow" to "on fire" in my experience, more detail would be helpful Smilie But several problems show themselves on first look:

That's not how if works. You're missing the then:

Code:
if [ "$weevils" -lt 5 ]
then
        echo "water buffaloes require immediate feeding"
else
        echo "everything's okay"
fi

That's not how find works either. I can't tell what you're even trying to do.

You can't use continue anywhere that's not in a loop, and I don't know what you were trying to do with it there.

How about:

Code:
[ -f "~/.recyclebin/$1" ] && [ -d "$2" ] && mv "~/.recyclebin/$1" "$2/$1"

# 6  
Old 03-05-2011
Thank for the hint. So this is my code so far for the rcvr command;

Code:
#!/bin/bash

if [ -f "~/.recyclebin/$1" ]

then

mv "~/.recyclebin/$1" "~/recovered"

else

echo "No file exists"

fi

When I entered
Code:
 $ rcvr filename

, it is supposed to move to the recovered directory. but when I checked it, no file was moved. What do you think is wrong with my code?
# 7  
Old 03-05-2011
If ~/recovered doesn't exist, it will move it to a file named 'recovered'.
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recycle bin.

Hi. I've created scripts for a recycle bin that can list, restore and empty it. I only have the problem of deleting two files with the same name. When I do it one file overwrite the other. What could I do to resolve it? The only thing I can think is asking the user to rename file before moving to... (2 Replies)
Discussion started by: ReonarudoB
2 Replies

2. UNIX for Dummies Questions & Answers

Recycle bin on minix 3.2.1?

Hi. I'm started to use minix 3.2.1 recently and I'm trying to create a recycle bin for it. I'm kinda struggling on how to do it. I searched internet and I found scripts created for it but I actually didn't learn how to create scripts in college and I'm not sure if I understand them. I just wanted... (1 Reply)
Discussion started by: ReonarudoB
1 Replies

3. Shell Programming and Scripting

Recycle Bin

what is recycle bin mode in unix??? (4 Replies)
Discussion started by: arun508.gatike
4 Replies

4. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

5. Homework & Coursework Questions

UNIX Recycle Bin - restore function

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A set of Linux shell scripts is required to allow users to ‘remove' files without them really disappearing until... (8 Replies)
Discussion started by: burn88
8 Replies

6. Shell Programming and Scripting

Recycle Bin Script

Hello, I have having problems with an assignment and am pretty desperate. My assignment is to create a shell script that does a Recycle_Bin tasks. You can only open this with PuTTY software or Knoppix. Perhaps on other software that are able to read linux language. My part is stuck... (2 Replies)
Discussion started by: chueu
2 Replies

7. Shell Programming and Scripting

intro to UNIX - making a sort-of recycle bin (for fun)

Hello, I'm only taking Intro to UNIX in school right now, so please bear with me. My problem is with a sort-of recycle-bin rig I've created for fun. I'm using Ubuntu 9.04, I am the admin. (only user, actually) of this computer. I'm using this script in ~/.bashrc # if files exist, remove contents... (6 Replies)
Discussion started by: jzacsh
6 Replies

8. Windows & DOS: Issues & Discussions

Path of Recycle Bin on Windows

hello everybody, I am trying to find the path of the Recycle Bin. I know that it's a temporary storage place, but it should have a path that we can refer to. I want to know it because I sometimes use cygwin to work on Windows, and when you delete something with it, it's gone. I just checked... (4 Replies)
Discussion started by: milhan
4 Replies

9. Linux

how to view the code form /bin/sh

How do we view th ecode for executables?? qwk,grep.fgrep, etc.. any ideas?? as they are written in C , I think , there should be some place where they are placed. (2 Replies)
Discussion started by: singh85
2 Replies
Login or Register to Ask a Question