News for hackers. Stuff that matters.
Re:Bash functions are better than I thought by presto8 on Sunday October 31, 2021 @08:17PM (#29061791)
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"

There are no comments on this comment yet.