[K12OSN] while read do questionts

Michael C Wescott wescott at sc.rr.com
Sat Feb 5 01:22:17 UTC 2005


On Fri, 2005-02-04 at 07:06, cliebow at downeast.net wrote:
[...]
> echo "uid: $name"
> echo "uidNumber: $uid"

Presumeably, uid is set before the script is called since it is not
initialized before it is first used.

[...]
> let "uid +=1"
> done
> 
> ok coders: can you get me round this stupid brain-flattulence. run 2000
> users thru this piece of script and uid increments on each pass.so at end
> of script uid otter be 2027 or summat..

In the script it is 2027 right up the script dies. When the process
running the script dies that value dies with it and you're left with
whatever it was set to before the script started.

Variables, like uid or PATH, are not kept in some global area common to
all of your processes. Instead they are local to each process, with the
initial values inherited from the parent process. When a process, like a
shell script, changes the value it does so for its own copy. To do what
you want, you'll have to explicitly save the value somehow, say in a
file.





More information about the K12OSN mailing list