I currently have this script set up for $1 $2 which takes two inputs, one an extension, one the file name, and searches for the file name in the relative path, if found, replaces the file with the new extension (or does nothing if same extension), and if not found, prints the error message.
#!/bin/csh
set ext="$1"
set oldName="$2"
if (-r "$oldName") then
set newName=`echo "$oldName" | sed 's/\.[A-Za-z0-9]*$/'".$ext"'/g'`
if ( "$oldName" == "$newName" ) then
:
else
mv "$oldName" "$newName"
endif
else
echo "$oldName": No such file
endif
What I need is to modify this script so that $1 is always the extension, but $2 can be any number of possible inputs, for example:
./chExt.sh 'bat' 'bool.com' 'nofilefound.biz' 'james.bro'
and would essentially make
bool.bat
nofilefound.biz: No such file
james.bat
so it would always read the $1 as the extension, and always see $2-$n as needing the same processes applied as the original script.
I have to use "foreach"'s and "shifts" specifically.