|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
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 Code:
Here Inside while ... done loop: VAR = New 10 VAR = Old 9 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 |
|
|||
It is the pipeline that is the cause for spawning the sub-shell:
Code:
#!/bin/sh VAR=Old pgrep sh | wc -l echo Entering the loop # echo A | while read REPLY; do while read REPLY; do echo Here VAR=New echo "Inside while ... done loop: VAR = $VAR" pgrep sh | wc -l if [ "X$REPLY" = X"Q" ] ; then break fi done echo Back to main program: VAR = $VAR pgrep sh | wc -l Code:
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
Thank you J65nko, that is great practical detective work!
Tomorrow I'll have to re-look at some man pages and see what they say about spawning a sub-shell in such circumstances (or don't say, as the case may be). |
|
||||
Here are a few selected quotes from man pages, which confirm what J65nko observed.
Quote:
Quote:
Quote:
The above are examples of what I called "unexpected" behaviour. So far so good. Now an oddity. The SunOS ksh has "expected" behaviour, but its man page says: Quote:
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Identify rules to behaviour | Droid | OpenBSD Security | 5 | 25th March 2012 05:58 PM |
DragonflyBSD: unexpected pkg_admin running. | colonelmooch | Other BSD and UNIX/UNIX-like | 0 | 4th August 2011 04:26 PM |
Am I blind? syntax error: `(' unexpected | guitarscn | Programming | 1 | 10th November 2010 08:53 PM |
strange behaviour after improper shutdown | karri | FreeBSD General | 1 | 15th October 2008 03:08 PM |
Funny network behaviour :) | PatrickBaer | General software and network | 5 | 9th October 2008 09:47 AM |