[PLUG] Maybe not so dumb BASH question
William A Morita
wamorita at hevanet.com
Thu May 5 19:03:51 UTC 2005
I have written the script below and am puzzled by the fact that the shell
variable TMPFILE is not global in nature.
According to all documentation I can find, it is explicitly stated that with
regard to function, all variables are global unless the "local" keyword is
used.
I am not seeing a global effect when the script below is run on White Box
Linux (Bash 2.05) or Fedora Core 3 (Bash 3.05). Is there a setting I may
have wrong someplace?
==============================
#!/bin/bash
# Script to get unique number using files in a temp directory
#
set -x
TMPDIR=~/tmp
function GetNumber
{
set -xv
for n in 0 1 2 3 4 5 6 7 8 9
do
TMPFILE=$TMPDIR/TagFile$n
if [ -f $TMPFILE ]
then
continue
else
touch $TMPFILE
echo $n
trap "rm -f $TMPFILE" INT TERM
exit
fi
done
}
TMPFILE=None
Num=`GetNumber`
echo $Num $TMPFILE
==============================
- Bill
wamorita at hevanet.com
Home: (503) 697-6994
Cell: (503) 260-3876
More information about the PLUG
mailing list