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