Shell tips and tricks

Ric Werme ewerme at comcast.net
Thu Nov 1 20:01:15 EDT 2007


> One trick which I've used to get around this is:

>  foo=44
>  p1 | while read line
>  do
>      dosomething > /dev/null 2>&1 # redirect output somewhere safe
>      foo=$((foo + 1))
>      echo MAGIC "$foo" #use magic just in case unexpected output reaches stdout
>  done | grep ^MAGIC | tail -n 1 | {
>   read magic foo
>   echo "foo = $foo"
>   # the rest of the code which needs access to foo
>  }

That is truly aw(e)ful, you should be ashamed of yourself!  Umm, I
need to keep a copy somewhere.  It would be good for passing
environment variables up the process tree too.

    -Ric Werme


More information about the gnhlug-discuss mailing list