LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 11-25-2012, 01:53 AM   #16
mohitnarula
LQ Newbie
 
Registered: Oct 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled

New Screenshot added, but it still not working..

Last edited by mohitnarula; 11-26-2012 at 11:05 AM.
 
Old 11-25-2012, 02:22 AM   #17
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
In any case, you should once try with the code I had suggested. Then if you face any problem, feel free to let us know.
Meanwhile, go through some scripting basic, so you can come to know where you're making mistake.
Here is useful content on shell scriping: http://tldp.org/LDP/abs/html/
 
Old 11-25-2012, 03:37 AM   #18
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Code:
#!/bin/bash

# Restore


restore='grep $1 $HOME/Paths'

filename='basename "$restore"'

location1='readlink -f $location'

# End
This doesn't work because you're storing the literal strings such as grep $1 $HOME/Paths in the variables instead of just storing the output of those commands. Maybe you wanted to use backticks (or even better, $( )) instead of single quotes?
Also, you still forget to quote your variables. Whenever you use a variable in your script, put it in the double quotes unless you want bash to split it. I would suggest that you also test your script with filenames that contain spaces.
That said, are you sure that your delete and trash scripts are working correctly? After deleting a file, is the file really there in the Dustbin directory?

Again, I would question the point of the Paths file. Why do you store the original paths of deleted files? You don't use it anyway. Instead, you ask the user where to move the file.

Can you also show an example of your Paths file as it looks now?
 
Old 11-25-2012, 10:39 AM   #19
mohitnarula
LQ Newbie
 
Registered: Oct 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Exclamation

Quote:
Originally Posted by shivaa View Post
In any case, you should once try with the code I had suggested. Then if you face any problem, feel free to let us know.
Meanwhile, go through some scripting basic, so you can come to know where you're making mistake.
Here is useful content on shell scriping: http://tldp.org/LDP/abs/html/
The above screenshot shows that I changed my Restore script to yours and below that when I did Restore, I'm getting those errors stated in the picture..
 
Old 11-25-2012, 11:41 AM   #20
mohitnarula
LQ Newbie
 
Registered: Oct 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Exclamation

[QUOTE=millgates;4836424]
Code:
#!/bin/bash

# Restore


restore='grep $1 $HOME/Paths'

filename='basename "$restore"'

location1='readlink -f $location'

# End
This doesn't work because you're storing the literal strings such as grep $1 $HOME/Paths in the variables instead of just storing the output of those commands. Maybe you wanted to use backticks (or even better, $( )) instead of single quotes?

This is how it looks after using backticks instead of single quotes..

Code:
#!/bin/bash
# Restore
restore =$(grep $1 $HOME/Paths)
filename=$(basename "$restore")
location1=$(readlink -f $location)

Also, you still forget to quote your variables. Whenever you use a variable in your script, put it in the double quotes unless you want bash to split it. I would suggest that you also test your script with filenames that contain spaces.
Code:
This is actually seems to be working without it, but I'm just getting this error now when I am doing restore "a"

readlink: missing operand
Try 'readlink --help' for more information.
That said, are you sure that your delete and trash scripts are working correctly? After deleting a file, is the file really there in the Dustbin directory?

Code:
Good point, for some reason, it working absolutely fine in Puppy Linux, but it ain't working in Fedora 15. Dunno why..
Again, I would question the point of the Paths file. Why do you store the original paths of deleted files? You don't use it anyway. Instead, you ask the user where to move the file.
Code:
The point of this file is, like how WINDOWS Recycle Bin works, so if you Restore a file from Recycle Bin, it goes back to its Original Location.
Can you also show an example of your Paths file as it looks now?
Code:
Yes, sure

# touch a
# del a
Are you sure you want to move this file to the Recycle Bin? (Yes/No)
y
# cat Paths
/root/123
/root/1
/root/a
# restore a
readlink: missing operand
Try 'readlink --help' for more information.
#
That's how it is just now. And, plus Del is delete the files which got the spaces in between too...

Last edited by colucix; 11-27-2012 at 04:16 PM. Reason: idem
 
1 members found this post helpful.
Old 11-25-2012, 11:46 AM   #21
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Quote:
Originally Posted by shivaa View Post
But changing rm=$(rm -i); rm $line to rm -i $line will not make any difference.
Yes it will:

Code:
~/tmp$ touch afile
~/tmp$ line=afile
~/tmp$ rm=$(rm -i); rm $line
rm: missing operand
Try `rm --help' for more information.
~/tmp$ touch afile
~/tmp$ rm -i $line
rm: remove regular empty file `afile'? y
~/tmp$
 
Old 11-25-2012, 12:52 PM   #22
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Code:
#!/bin/bash
# Restore
#      You should definitely put double quotes
#        +---------- here ----------+
#        |       here   and here    |
#        |       |  |  /         \  |
#        v       v  v v           v v      
restore ="$(grep "$1" "$HOME/Paths")"
#      ^
#      |
# can you see this space?
# It is not supposed to
# be there.

filename="$(basename "$restore")"
location1="$(readlink -f "$location")"
#                          ^
#                          |
#              What's this? $location does
#              not exist in your script.
 
Old 11-26-2012, 06:03 AM   #23
mohitnarula
LQ Newbie
 
Registered: Oct 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Exclamation

#!/bin/bash
# Restore
# You should definitely put double quotes
# +---------- here ----------+
# | here and here |
# | | | / \ |
# v v v v v v
restore ="$(grep "$1" "$HOME/Paths")"
Code:
 1. done that, haven't changed anything I guess, as it is still not working.
# ^
#
# can you see this space It is not supposed to be there.?
Code:
 2. That was a typing error, my bad! There isn't any space in the actual script.
#
filename="$(basename "$restore")"
location1="$(readlink -f "$location")"
# ^
# |
# What's this? $location does
# not exist in your script.
Code:
 I tried changing it to $1 &  $restore but ain't doing anything. I'm not getting any error messages now but it's still not moving the file from the Dustbin to the Original Location while reading the location from the Path file.

Last edited by colucix; 11-27-2012 at 04:16 PM. Reason: idem
 
Old 11-26-2012, 06:42 AM   #24
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Code:
location1="$(readlink -f "$location")"
how about something like this?

Code:
#!/bin/bash

mv -i "$1" "$(grep "$1" "$HOME/Paths")"
Assuming you also check that the grep found anything and that "$1" exists, the destination directory exists etc.

That said, this is still not very robust and has a lot of drawbacks. What if you delete two files that are in different locations but have the same filename?

I would probably make the remove rename files so they have unique filenames when they are moved to the Dustbin. Then I would probably store two things in the Paths file: the new filename and the original path and filename. Associative arrays might come handy. Nice exercise for bash scripting. Or use a database, such as SQL.
 
Old 11-26-2012, 10:58 AM   #25
mohitnarula
LQ Newbie
 
Registered: Oct 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Smile Thanks alot for your help MILLGATES, you're a LEGEND!

Code:
location1="$(readlink -f "$location")"
that didn't work too.. but somehow I managed to get it done now.

Code:
 What if you delete two files that are in different locations but have the same filename?
Yes, that's a good point too, how do think I can change my script to add this feature as well?

Last edited by colucix; 11-27-2012 at 04:16 PM. Reason: idem
 
Old 11-26-2012, 11:01 AM   #26
mohitnarula
LQ Newbie
 
Registered: Oct 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Smile All done finally!

Thanks everyone I have finally managed to get all the 3 scripts done. All of it is working fine. Thanks alot for helping me out and sharing your knowledge with me. APPRECIATE IT.

Last edited by colucix; 11-27-2012 at 04:17 PM.
 
Old 11-26-2012, 11:23 AM   #27
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Oh, sorry, I seem to have lost the begining of my previous post... I quoted this line from your script

Code:
location1="$(readlink -f "$location")"
to ask you what was the point of that statement.
 
Old 11-27-2012, 04:27 PM   #28
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Moderator note: @mohitnarula: I have restored all the content you deleted in this thread. Sincerely I don't see any reason for such a behaviour which is contrary to the spirit of the LQ community, where solutions, comments or advices may serve others to solve similar issues. Moreover, it is not fair towards people that helped you here in a very constructive way.

Said that, please refrain from doing this in the future. Instead, if you wish to remove your posts/threads, contact an administrator of the forum (for example by reporting your own post), explain your reasons and ask him to take a proper action. Nuff' said.
 
1 members found this post helpful.
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/usr/bin/time Shell Scripting Function solo2 Programming 7 10-12-2011 05:25 AM
Delete a lin from crontab using shell scripting srinivasj Programming 3 07-08-2009 12:46 AM
Delete files from user recycle bin 7ser23 Linux - Newbie 4 10-19-2008 10:14 PM
change trash caption to ReCycle Bin javid67 Linux - General 4 12-18-2006 06:22 AM
How to delete the trash bin? BajaNick Linux - Software 4 08-20-2003 01:37 PM


All times are GMT -5. The time now is 09:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration