#!/bin/sh

[ -z "$HOGE" ] && { ./example | HOGE=hage exec $0; }

while read x; do
 なんか処理して echo 処理結果
done