Assignment 6

Scripting

Assigned
Due

Nov 2
45 pts
Nov 19

Create a shell script which takes two command line options, a stem and an extension. It then renames every (non-hidden) file in the current directory having the expecified extension with a name of the following form:

stem_NNNN.exten
where exten is the specified extension and stem the specified stem, and NNNN is a four-digit count starting from 1. For instance:
[bennet@desktop test]$ ls Makefile asst2.html asst4.html asst6.in index.m4 alvin.txt asst2.in asst4.in boris.txt missing_parts.txt asst1.html asst3.html asst5.html disk_partition_asst.in asst1.in asst3.in asst5.in elwood.pdf [bennet@desktop test]$ sequify.sh web html [bennet@desktop test]$ ls Makefile asst3.in boris.txt missing_parts.txt web_0004.html alvin.txt asst4.in disk_partition_asst.in web_0001.html web_0005.html asst1.in asst5.in elwood.pdf web_0002.html asst2.in asst6.in index.m4 web_0003.html [bennet@desktop test]$ sequify.sh src in [bennet@desktop test]$ ls Makefile index.m4 src_0003.in src_0007.in web_0004.html alvin.txt missing_parts.txt src_0004.in web_0001.html web_0005.html boris.txt src_0001.in src_0005.in web_0002.html elwood.pdf src_0002.in src_0006.in web_0003.html [bennet@desktop test]$

Hint: The Unix printf command can be used to pad a number to a given width. For instance, printf "%04d" 16 will print 0016, without a newline. If you keep a counter in a shell variable N, then $(printf "%04d" $N) will generate the padded number as part of a command, or on the right side of a variable assignment

Once you have created your files, send them to me here. If you create it on Sandbox, you can copy it off using WinSCP, FileZilla or any client that supports the scp protocol. Or just run this from Sandbox:

links http://sandbox.mc.edu/cgi-bin/submit/submit.cgi/twbsubmit/numscript