Please need help with detail instructions. Thank you Unix Shell Scripting and Ma
ID: 3752330 • Letter: P
Question
Please need help with detail instructions. Thank you
Unix Shell Scripting and Makefile
1. Write a script safe_rm, which does all of the following:
.It takes one argument, which is a file name with no wildcard expressions.
.If this file does not exist in the current directory, report "file does not exist!".
.If this file do exist, make a copy of it by attaching at the end ".bak", and then remove the original file.
For example if there is a file with the name "foo.c" in the current folder, by running:
./safe_rm foo.c
the program should create a le called "foo.c.bak", which is exactly the same as "foo.c" except
for the name; and the original file "foo.c" should be deleted.
Explanation / Answer
Given below is shell script for the quesiton. Please do rate the answer if it helped. thank you
#!/bin/sh
if [[ $# -ne 1 ]]; then
echo Please provide file name to be removed
exit
fi
fname=$1
if [[ -f $fname ]]; then
cp $fname $fname.bak
rm $fname
else
echo $fname does not exist!
fi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.