In: Computer Science
In many versions of unix there is an -i option for rm so that you will be prompted for confirmation if you are about to delete a file. Write a script called rmi which will prompt without using the -i argument
Below given is a shell script with name rmi.sh
-----------------------------------------------
#!/bin/bash
##below statement takes the filename from commandline
filename=$1
## below if loop checks whether the file with the given name exists
or not
if [[ -f $filename ]];
then
## below line prompts for asking to delete the given file or not
and reads the answer to the variable ans
read -p "Do you want to delete
the file $filename ? [y/n]" ans
## below if loop checks whether the want to remove the file or
not
if [[ $ans == [yY] ]];
then
## this portion deletes the file with the given name if answer is
Y/y and print the message
rm "$filename"
echo "$filename deleted"
else
echo "$filename not deleted"
fi
else
##if the given file not exist, it will print the message
echo "$filename does not
exist"
fi
------------------------------------------------
Output of the program is shown below