This is my remove script. Not sure why my project is unresponsive, It doesn't give an error, it just doesn't do anything when I type "sh remove filename" into the command line. I have to hit CTRL C to exit. Ignore the line numbers. I posted my code and what I have to do below:
Create script named remove
Create a recycle bin in $HOME/deleted in your script
For any file to be deleted, it will be a command line argument and the script should executed as follows: sh remove fileName.
The script must test for the same error conditions as the rm command and display the same error messages as the rm command
The filenames in the recycle bin should be in the following format: filename_inode
#!/bin/bash
2 sh remove "filename"
3 function directory(){
4 #Makes the deleted directory
5
6 if [ ! -d ~/deleted ]
7 then
8 mkdir ~/deleted
9 fi
16}
17 function movefile(){
18 #moving files to recycle bin
19 mv $l ~/deleted/$l
20 echo "File moved to recycle bin "
21 }
22
23
24 function error_conditions(){
25 #prints error messages
26 if [ ! -f ~/project ]
27 then
28 echo "sh: remove: cannot remove '$filename': no such file or directory"
29 elif [ ! -d ~/project ]
31 then
32 echo "sh remove: cannot remove '$filename': is a directory"
33 else
34 echo "sh remove: missing operand"
35 fi
37 }
38
40 function delete_file(){
41 #gets inode for filename
42 inode=$(stat -c%i $filename)
43 filename=$1
44 pwd=$(readlink -e$filename)
45 if $interactive
46 then
if $verbose = true ]
47 read -p "Are you sure you want to delete $filename?" i_input
48 if [ $i_input = "y" ] || [ $i_input = "Y" }
49 then
50 mv $filename ~/delete/${filename}_$inode
51 fi
52 fi
53 }
54 directory
55 error_conditions $*
56 delete_file $*
57 move_file $*
removescript? In that case, it is calling itself recursively on the first line (well, line 2). Removesh remove "filename"from that line../remove whateverfile. The script should not call itself recursively. If you want to have it execute wheneverrmis used, you would probably wrap it in an alias or shell function that you declare in your shell's startup files. But that's a later issue, you have a number of other issues in the code that you will have to deal with first.mv. A script that acts likermwould actually remove files. You want your script to move files. In any case, the script should not need to call itself.~deletedwill try to access the home directory of a user calleddeleted. Theerror_conditionsdoes not look at$filename.$filenameis not double quoted, so the script won't handle filenames with spaces, for example. You pass$*(unquoted, should be"$@") to shell functions that does not use their arguments. You have function calledmovefile, but callmove_file. You seem to call bothdelete_fileandmove_fileand they both move the file (althoughmovefileuses the unset variable$l). There's a[missing in a test.$interactiveseems to be unset.