Looks like I figured it out:
Code:
#!/bin/bash \
fileExt="$1"
shift
for oldName in $*
do
if test -r $oldName;
then
newName=`echo $oldName | sed 's/[^\.]*$/'$fileExt'/'`
mv $oldName $newName >& err.out
else
echo $oldName: No such file
fi
done
Thanks for the help! This works as expected. I now need to go back through and check over the rest of it. We submit it through an "auto grader" tool that checks the script vigorously for many cases...
EDIT: Got it to work for all cases - Seems like that was insane. He said "test it" before submitting, I didn't think he'd cover so many cases!
Code:
#!/bin/bash \
fileExt="$1"
shift
oldName="$1"
#for oldName in $*
while test "$oldName" != "";
do
if test -r "$oldName";
then
newName=`echo $oldName | sed "s/[^\.]*$/$fileExt/"`
mv "$oldName" "$newName" >& err.out
else
echo $oldName: No such file
fi
shift
oldName="$1"
done
What have I learned here? You have to use double quotes for your shell variables that contain spaces instead of single quotes - or so it seemed here -. Seems like that was the biggie here. Aside from bash's ..........ing about whitespace in variable assignment... Seems really picky and sloppy to me.