On Sat, Jun 29, 2024 at 6:39 AM Zachary Santer <zsan...@gmail.com> wrote: > command this-file | > while IFS='' read -r -d '' path; do > cd -- "${starting_PWD}/${path}" > if [[ -r this-file ]]; then > recursive_function "${entry_path}/${path}" > fi > # fill arrays > # there is another anonymous pipe here, as well > done > # > if (( PIPESTATUS[0] != 0 )); then > printf '%s\n' "command failed" >&2 > error='true' > fi > cd -- "${starting_PWD}" > }
You can avoid pipe recursions by storing the output first in an array. There's also no need to use an error flag variable. Just make sure return calls are chained. ------------------------- local temp command this-file | readarray -d '' temp # -d is a Bash 5.0 feature. if (( PIPESTATUS[0] != 0 )); then printf '%s\n' "command failed" >&2 return 1 fi for path in "${temp[@]}"; do cd -- "${starting_PWD}/${path}" || return if [[ -r this-file ]]; then recursive_function "${entry_path}/${path}" || return fi ... done cd -- "${starting_PWD}" ------------------------- You can also just use a 'die' function if cleanups aren't needed. Anything is valid in a contained code. -- konsolebox