Refreshing a file in bash

I am creating a file when running a bash script as shown. I want to refresh the file every time, however touch only changes the time stamp. I also need the file with execute permission. I have included redirection ">" the first time to solve the problem (i=1).

Any suggestions how I can simplify this better?

execfl="rmlines#${arg_rexp}.x"

touch $execfl
chmod a+x $execfl

i=1
for f in $arg_files ; do
  echo "titl = $f"
  name="`echo $f | sed -e 's|.[^.]*$||'`"
  extn="`expr $f : '.*\.\([^.]*\)$'`"
  intmd_fl="$f.intmd"
  if [ $extn != "x" ]; then
    echo "$i"
    if (( i == 1 )); then
      echo "grep -v "$rexp" $f > $intmd_fl" > $execfl
    else
      echo "grep -v "$rexp" $f > $intmd_fl" >> $execfl
    fi
    echo "mv $intmd_fl > $f" >> $execfl
    echo "" >> $execfl
  fi
  ((i++))
done

---------- Post updated at 08:01 AM ---------- Previous update was at 07:39 AM ----------

Modified to the following. A bit better now.

  execfl="rmlines#${arg_rexp}.x"

  i=1
  for f in $arg_files ; do
    name="`echo $f | sed -e 's|.[^.]*$||'`"
    extn="`expr $f : '.*\.\([^.]*\)$'`"
    intmd_fl="$f.intmd"
    if [ $extn != "x" ]; then
      if (( i == 1 )); then
        echo "grep -v "$arg_rexp" $f > $intmd_fl" > $execfl
      else
        echo "grep -v "$arg_rexp" $f > $intmd_fl" >> $execfl
      fi
      echo "mv $intmd_fl $f" >> $execfl
      echo "" >> $execfl
    fi
    ((i++))
  done

# permit execution
  chmod a+x $execfl

Here you can just use >> as it create the file as well. No need for a check here.

To get the file name you can use:

name=${f%.*}

and to get the extension you can use

extn=${f##*.}

Not if the user executed the script a second time. That's why I used ">" first time

If you want to clear the file before the script is executed, why not just do that first?

Will need to clear the file if it exists then. What would you call fir doing this?

To check if the file exists and then clear it use

[ -f $execfl ] && > $execfl

And why would you want check if the file exists in the first place? Anyway you are creating the file. So you can just do

 > $execfl 

before the loop insted of including a check for the file.