[PLUG] Maybe not so dumb BASH question

William A Morita wamorita at hevanet.com
Fri May 6 17:16:06 UTC 2005


Charles,

The value of "None" should be overwritten by the value set in the function.
That is if the documentation is correct then TMPFILE is a global variable.

- Bill 
wamorita at hevanet.com 

 

-----Original Message-----
From: plug-bounces at lists.pdxlinux.org
[mailto:plug-bounces at lists.pdxlinux.org] On Behalf Of Charles Sliger
Sent: Thursday, May 05, 2005 9:51 PM
To: wamorita at hevanet.com; 'General Linux/UNIX discussion and help;civil and
on-topic'
Subject: RE: [PLUG] Maybe not so dumb BASH question

Works for me.
GNU bash, version 2.05b.0(1) - release (i386-pc-linux-gnu) Running on Ubuntu
5.04

What problems were you seeing?

Charles L. Sliger,    Information Systems Engineer,    chaz at bctonline.com
"no matter where you go, there you are..."


-----Original Message-----
From: plug-bounces at lists.pdxlinux.org
[mailto:plug-bounces at lists.pdxlinux.org] On Behalf Of William A Morita
Sent: Thursday, May 05, 2005 12:04 PM
To: 'General Linux/UNIX discussion and help; civil and on-topic'
Subject: [PLUG] Maybe not so dumb BASH question

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 


_______________________________________________
PLUG mailing list
PLUG at lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

_______________________________________________
PLUG mailing list
PLUG at lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug




More information about the PLUG mailing list