bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with Script Variables


From: Matheny, Rob
Subject: Problem with Script Variables
Date: Thu, 14 Oct 2004 16:11:00 +0100

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' -DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8' -DCONF_VENDOR='sun' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib  -DNDEBUG -I/usr/local/BerkeleyDB.4.2/include -I/usr/local/ssl/include -I/usr/openwin/include -I/usr/local/lib/glib-2.0/include -I/usr/local/include -g -O2

uname output: SunOS hdels1 5.8 Generic_117000-03 sun4u sparc SUNW,Sun-Blade-1000
Machine Type: sparc-sun-solaris2.8

Bash Version: 3.0
Patch Level: 0
Release Status: release

Description:
        [In bash scripts I have noticed that if I have a variables inside 'for while' loops that after the 'done' statement the loop variables are not accessable. Ie echo $var has no value where it just did inside the loop. Below is and example of where I found this behavior. Please look at the fileline variable which is affected by the above stated condition. 


#!/bin/bash
#BUILD ARRAY
libname=$1
docnumber=$2
arrayfileline=1
cat ${libname}.log | tr -d "\0" > ${libname}2.log
rm ${libname}.log
cat ${libname}2.log | while read LINE
do
 export fileline[$arrayfileline]=$LINE
 ((arrayfileline=arrayfileline+1))
 linecount=`echo ${#fileline[*]}`
 echo $linecount > /tmp/linecount
done
################
getarrayline=1
linecount=`cat /tmp/linecount`
linestat=go
while [ $linestat == go ]
do
 echo "ARRAY LINE ${fileline[$getarrayline]}"
 echo ${fileline[$getarrayline]} | grep $docnumber > /dev/null
 if [ $? -eq 0 ] #FOUND DOC IN NDX LOG
 then
  ((getnextline=getarrayline+1))
  echo "${fileline[$getarrayline]} ${fileline[$getnextline]}"
 fi
 ((getarrayline=getarrayline+1))
 if [ $linecount == $getarrayline ]
 then
  linestat=nogo
 fi
Done]

Repeat-By:
        [#!/bin/bash
#BUILD ARRAY
libname=$1
docnumber=$2
arrayfileline=1
cat ${libname}.log | tr -d "\0" > ${libname}2.log
rm ${libname}.log
cat ${libname}2.log | while read LINE
do
 export fileline[$arrayfileline]=$LINE
 ((arrayfileline=arrayfileline+1))
 linecount=`echo ${#fileline[*]}`
 echo $linecount > /tmp/linecount
done
################
getarrayline=1
linecount=`cat /tmp/linecount`
linestat=go
while [ $linestat == go ]
do
 echo "ARRAY LINE ${fileline[$getarrayline]}"
 echo ${fileline[$getarrayline]} | grep $docnumber > /dev/null
 if [ $? -eq 0 ] #FOUND DOC IN NDX LOG
 then
  ((getnextline=getarrayline+1))
  echo "${fileline[$getarrayline]} ${fileline[$getnextline]}"
 fi
 ((getarrayline=getarrayline+1))
 if [ $linecount == $getarrayline ]
 then
  linestat=nogo
 fi
Done.]


Cheers,
Rob Matheny
CLASSIFICATION UNCLASSIFIED



All e-mail sent and received by NCIS is scanned and archived for a minimum of one year. e-mail may be passed at any time and without notice to an appropriate branch within NCIS, on authority from the Director General or his Deputy, for analysis
This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the NCIS Security Officer.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

reply via email to

[Prev in Thread] Current Thread [Next in Thread]