title: change file extension in unix
body: <p>I am taking a intro to Unix class and am stuck on the final assignment.  I need to write a script to change the file extension of a filename that is input when the script is run.  The new file extension is also input when the script is run.  The script is call chExt1.sh . Our first trial of the script is run as follows</p>
  
  <pre><code>./chExt1.sh cpp aardvark.CPP
  </code></pre>
  
  <p>The script is suppose to change the second input file extension to the file extension given in the first input.  It is not suppose to matter what file extension is given with the file name or what file extension is given as the new extension, nor is it only for changing uppercase to lowercase.  In hope to make this very clear if given the following:</p>
  
  <pre><code>./chExt1.sh istink helpme.plEaSe
  </code></pre>
  
  <p>The script would change helpme.plEaSe to helpme.istink .  I have searched on this forum and in google and have had no look with trying the different examples I found.  Below is some of the examples I have tried and what I currently have.
  Current</p>
  
  <pre><code>#!/bin/sh
  fileExtension="$1"
  shift
  oldName="$2"
  shift
  newName=${oldName%%.*}${fileExtension}
  echo $newName
  </code></pre>
  
  <p>The echo is just to see if it works, and if I get it working I'm going to add an mv to save it.
  Others that I have tried:</p>
  
  <pre><code>newName=`${oldName%.*}`
  newName=`${oldName#.*}`
  sed 's/\.*//' $oldName &gt; $newName
  </code></pre>
  
  <p>I can't seem to find some of the other sed I have used but they involved alot of backslashes and () with .* in there.  I did not try the basename command cause I don't know the file extension to be entered and all I the examples I saw required that you specify what you wanted removed and I can't.  I did not list all the different quote variations that I used but I have tried alot.  My instructions say to use the sed command since we should know how to use that from class but when I try to do it I don't isolate just the ending of the file and I believe (cause it takes so long to finish) that it is going through the whole file and looking for .'s and anything after cause I kept doing .* as the pattern.  Thanks for anyhelp you can give.</p>