View Single Post
  #2   (View Single Post)  
Old 20th May 2013
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

The following is tested on OpenBSD

A new shell is spawned to handle the pipeline and while ... done loop:

Code:
#!/bin/sh

VAR=Old

echo A | while read REPLY; do
    echo Here
    VAR=New
    echo "Inside while ... done loop: VAR = $VAR"
    pgrep sh | wc -l
done

echo VAR = $VAR
pgrep sh | wc -l
Running this produces:
Code:
Here
Inside while ... done loop: VAR = New
      10
VAR = Old
       9
So there is one more shell running inside that loop. The variable is set to within that sub-shell and this sub-shell cannot modify the variable of the parent shell/process.

If you mess around with shell commands in Makefiles you encounter similar issues
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote