I'm trying to create a shell script file that uses getopts. The purpose of the program is to remove files that are in the project and place them in the deleted directory aka recycling bin. I have already been able to successfully complete this.
I have also been able to use the getopt command -i (interactive) to pass into a case statement and then trigger off a question for the user asking if they are sure they would like to remove a file.
This has been done by creating a variable "ision" and setting it to true when the case statement is activated. I have inserted my code down below. I've tried it out a couple of times and everything seems to be fine but I would like to add the verbose activity/mode. Is there anyone who could help me out?
#!/bin/bash while getopts ":i:v" option ; do case "$option" in i) echo "interactive mode set" ision=true; break;; v) echo "verbose mode" vison=true; break;; esac done echo "this is the proof we need" echo $@ shift $(($OPTIND-2)) echo $@ echo "this is working too" if [ ! -e ~/deleted ] then mkdir ~/deleted fi echo "the echo file was made or just created" if [ $# -eq 0 ] then echo "safe_rm missing operand" exit fi echo "all workking on the western front" for i in $@ do if [ "$ision" == "true" ] then echo "do you want to remobve the file" echo "variable test $i" echo "yes or no" read -p "Enter " answer if [ "$answer" == "no" ] then continue; fi fi if [ ! -f $i ] then echo "no such file or directory" exit fi if [ $i == safe_rm ] then echo "cant remove safe_rm" continue fi if [ $i == safe_rm_restore ] then continue echo "cant remove safe_rm_restore" fi inode=$(ls -i $i | cut -c -6 ) echo "the inode is $inode " pathname=$(dirname $i) if [ $pathname == "." ] then pathname=$(pwd) echo $pathname fi basename=$(basename $i) path=$basename"_"$inode":"$pathname"/"$basename echo $path if [ ! -f .restoreinfo ] then touch .restoreinfo fi echo $path >> .restoreinfo mv $i ~/deleted/ done