#!/bin/tcsh

# Solution for BTM Lab 09, exercise 1
# author: Ronni Grapenthin

# loop over all existing files that match 
# the pattern *.qm; A list containing these
# filenames is being created by the '()' 
# (brackets as "list operator"). One item of this
# list is assigned to 'f' during each iteration of 
# the foreach loop. Hence, $f contains a different
# filename that ends in qm in each iteration.
foreach f (`ls *.qm`)
	# check whether archives exist for the current .qm
	# file. We can do this using the -e existence check
 	# of the if-statement and simply append a '.gz' to the
	# filename in $f
    if (-e ${f}.gz) then
		# I wanted you to echo the file that exists as
		# archive and qm file ...
		echo ./$f
	
		# ... and rename it by changing all lower case
 		# letters to upper case which we can do here:
		# I add the -v (verbose) option so that this action
		# is being echoed to the screen as well. 
		# mv SOURCE TARGET is the calling syntax for the mv 
		# command. $f is the source, the file that exists in 
		# archived form; the tr command translates lower case 
		# to upper case for $f in a subshell and returns a string
		# to the calling shell which will serve as a TARGET 
		# for the mv command.
		mv -v $f `echo $f | tr '[a-z]' '[A-Z]'`
    endif
end

# Doing this for archived files might be overkill since gzip 
# would just overwrite existing compressed files given the correct
# options. However, once in a while you might not know which version
# is which and rather than just deleting files, flagging them in a 
# certain way might come in handy.
