1. If writing in ksh use the shell built-in "print" instead of "echo".
2. If you post code here pls. use the [ code ] and [/ code ]-BBcodes
3. instead of using "expr" with backticks use "(( i += 1 ))"
4. open a file descriptor via exec and use "print -u[N]" to create output. This way you can open the file once at the start of the script and close it at the end. This way you can easily switch from append- to overwrite-mode:
Code:
#! /bin/ksh
typeset -i iCnt=0
exec 3>> /path/to/file # apend-mode
#exec 3> /path/to/file # overwrite-mode
while [ $iCnt -lt 5 ] ; do
print -u3 - "iCnt now at $iCnt"
(( iCnt += 1 ))
done
print -u3 - "--------------"
exec 3>&-
exit 0
bakunin