Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The DOS Rename command allows file suffixes to be changed so that: ren c *.cpp c

ID: 3786163 • Letter: T

Question

The DOS Rename command allows file suffixes to be changed so that: ren c *.cpp changes all files with suffixes .c to the suffix the name with .cpp. So a c is renamed a cpp; b.c is renamed b.ccp...for all files in the path Write a bash shell script that takes the destination path (directory dest as an optional parameter and renames all files in dest or current directory with old extension to new extension. The format is S proj3 [dest] old extension new extension It should query the user about each file before r (y or n skip if n (or no Example: Suppose files a.c b.c in the directory./dest A sample execution would be Sproj3 dest c cpp rename a c? (y/n)y rename b.c? Cy/n) n. finshed Sls dest should include a cpp b.c If no destination is provided, assume the current working directory is the destination which includes files a c, b.c

Explanation / Answer

#!/bin/bash

if [ $# -lt 2 ]
then
echo "No of arguments is not correct. It should be 2 or 3"
exit 1
elif [ $# -gt 3 ]
then
echo "No of arguments is not correct.It should be 2 or 3"
exit 1
elif [ $# -eq 3 ]
then
mv -i $1/*.$2 $1/*.$3
ls $1
exit 0
elif [ $# -eq 2 ]
then
mv -i *.$1 *.$2
ls
exit 0
fi

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote