Question: Write a script called ChangeExtensions that accepts two file name extensions as arguments, and renames all files with the first extension to have the

 Write a script called ChangeExtensions that accepts two file name extensions as  

Write a script called ChangeExtensions that accepts two file name extensions as arguments, and renames all files with the first extension to have the second extension. For example, Change Extensions txt text would change all .txt files to be .text files. Hint: read the man pages for basename. The script must check that two arguments have been provided, and exit with an error message if not. The script must check if there are any files with the first extension, and exit with an error message if there are none. If all goes well, a message must be output for each filename that is changed. (1.0%)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a script called ChangeExtensions that accepts two file name extensions as arguments and renames all files with the first extension to have the second extension It includes the checks for the number of arguments and the existence of files with the first extension bash binbash Check the number of arguments if ne 2 then echo Error Two arguments are required Usage ChangeExtensions oldextension newextension exit 1 fi Store the old and new extensions from the arguments oldextension1 newextension2 Check if there are any files with the old extension if ls oldextension 1 devnull 2 1 then echo Error No files found with the extension oldextension exit 1 fi Iterate over the files with the old extension and rename ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!