From owner-freebsd-hackers Fri May 23 20:21:00 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id UAA03048 for hackers-outgoing; Fri, 23 May 1997 20:21:00 -0700 (PDT) Received: from bitbox.follo.net (bitbox.follo.net [194.198.43.36]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id UAA03040 for ; Fri, 23 May 1997 20:20:57 -0700 (PDT) Received: (from eivind@localhost) by bitbox.follo.net (8.7.6/8.7.3) id FAA05443; Sat, 24 May 1997 05:20:40 +0200 (MET DST) Date: Sat, 24 May 1997 05:20:40 +0200 (MET DST) Message-Id: <199705240320.FAA05443@bitbox.follo.net> From: Eivind Eklund To: Steve Howe In-reply-to: Steve Howe's message of Fri, 23 May 1997 17:19:30 -0800 (AKDT) Subject: Re: pipelines References: Cc: hackers@freebsd.org Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk I've kept hackers on the Cc: line - if you reply to this, consider moving it to -questions. Thanks. > #!/bin/sh > # invoke with dummy args ... > while [ $1 ]; do t=$(($t + 1)); shift; done | cat; echo X$t > > > is there any way to find the value of a variable that is set in a pipe > ... outside the pipe? i wish i could echo "t"s value in the example > above, but exporting, etc, doesn't seem to help. No possible, AFAIK. Your '| cat' makes a sub-shell, which can't change the variables of the parent. Could you drop it? Otherwise (probably with your subject-line :-), you'll have to use temp-files, ie. #!/bin/sh # invoke with dummy args ... umask 77 if mkdir /tmp/dummy.$$ then export MYCOUNTER=/tmp/dummy.$$/counter echo -n 0 > $MYCOUNTER while [ $1 ] do echo -n $((`cat $MYCOUNTER` + 1)) > $MYCOUNTER shift done | cat echo X`cat $MYCOUNTER` rm -rf /tmp/dummy.$$ else echo "Unable to create temporary directory /tmp/dummy.$$!" exit 1 fi mkdir is to get secure temp-files. > please respond directly - i don't subscribe to hackers ... thanks. And you shouldn't post this there - it belong in -questions. Eivind.