Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help with my recycle bin code Post 302502372 by zel2zel on Monday 7th of March 2011 10:55:16 PM
Old 03-07-2011
Thanks to that the ls part now works. The only problem is that the file in the recycle bin directory doesn't move into the recovered_files directory.

Here's the script:

Code:
#!/bin/bash

eval set -- `getopt f:h: "$@"`

while [ $# -gt 0 ]
do
        case "$1" in
                -f)     shift ;
                        ls -l recovered_files
                        exit
                        ;;
                -h)     shift ;
                        ls -al recovered_files
                        exit
                        ;;


                --) break
                        ;;
        esac
        shift
done


#move the file from the recycle bin -- to --- > recovered_files directory

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

then

mv  ~/recyclebin/$1 ~/recovered_files/$1


else

echo "No file exists"

fi

It lists the recovered_files directory, but the file that is supposed to be in the recovered_files directory is not listed there. So the moving of file from the recycle bin to recovered_files directory didn't work right. Is the $1 in the if statements correct? How can I combine the getopt script with the recycble bin script?

---------- Post updated at 10:55 PM ---------- Previous update was at 08:17 PM ----------

Wah! The script is now working!

Here:

Code:
#!/bin/bash

eval set -- `getopt f:h: "$@"`

while [ "$#" -gt 0 ]
do
        case "$1" in
                -f)
                        if [ -f ~/.junkbin/$2 ] ;
                        then
                                mv ~/.junkbin/$2 ~/recovered_files/$2
                                echo " File is successfully recovered "
                                ls -l recovered_files
                        else
                                echo "File $2 does not exists "
                        fi
                        exit
                        ;;
                -h)     if [ -f ~/.junkbin/$2 ] ;
                        then
                                mv ~/.junkbin/$2 ~/recovered_files/$2
                                echo " Hidden file is successfully recovered "
                                ls -al recovered_files
                        else
                                echo "File $2 does not exists "
                        fi
                        exit
                        ;;


                --) break
                        ;;
        esac
        shift
done

I was planning to create a function so that I will not repeat the if [..] part anymore. but I dont know how to create a function. I think this script is enough already. Thanks Corona688 for your help! Godbless!

Last edited by zel2zel; 03-07-2011 at 11:28 PM.. Reason: Just encountered another problem
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. Shell Programming and Scripting

Recycle Bin

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

8. 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

9. 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
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. SunOS 5.10 30 Aug 2004 getusershell(3C)
All times are GMT -4. The time now is 01:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy