Hacker News new | past | comments | ask | show | jobs | submit login

Here is a script that shows exporting results from a subprocess to a parent shell using a temporary file:

  #!/usr/bin/env bash

  process_line() {
      if [[ $* == *foo* ]]; then
          echo "found_foo=1" >>$IPC
      fi
  }

  IPC=$(mktemp)
  find . -maxdepth 1 -type f | while read line; do
      # note: this is run a subprocess
      process_line "$line"
  done

  source "$IPC"
  echo "found_foo=$found_foo"



Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: