The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 12-13-2007
bakunin bakunin is offline
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,292
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
Reply With Quote