From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,215796c423b2640b,start X-Google-Attributes: gidf678f,public From: Daniele Fua Subject: sh script Date: 1998/11/04 Message-ID: <36406956.3F54@g24ux.phys.uniroma1.it>#1/1 X-Deja-AN: 408307902 Content-Type: multipart/mixed; boundary="------------FF6ABD31DF" X-Complaints-To: postmaster@caspur.it X-Trace: canarie.caspur.it 910190857 5127 141.108.5.136 (4 Nov 1998 14:47:37 GMT) Organization: University of Rome "La Sapienza", Italy Mime-Version: 1.0 NNTP-Posting-Date: 4 Nov 1998 14:47:37 GMT Newsgroups: comp.unix.osf.misc This is a multi-part message in MIME format. --------------FF6ABD31DF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Anyone can suggest why the attached small sh script for pseudo random number generation [0-99] is not able to keep the variable $rand outside the scope of the while loop? Any suggested fix? My operating system is Digital UNIX V4.0D Thanks -- =================================================================== | Daniele Fua` G24 | E-mail: fua@g24ux.phys.uniroma1.it | | Dept. of Physics | Phone : +39 06 4991 3515 | | Universita` "La Sapienza" | Fax : +39 06 4991 3522 | | P.le A. Moro, 2 | | | 00185 Roma, Italy | | =================================================================== --------------FF6ABD31DF Content-Type: text/plain; charset=us-ascii; name="random" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="random" #! /usr/bin/sh #rand=`expr 1` /bin/ps -e -o pid | while read mypid do if [ "${mypid}" != "PID" ]; then rand=`expr \( "${rand}" + "${mypid}" \) % 100` fi echo "inside loop: rand=" ${rand} done echo "outside loop: rand=" ${rand} --------------FF6ABD31DF--