fork download
  1. set -x # turn on trace logging
  2.  
  3. func1() { echo "func1 was in fact run for: $1"; }
  4.  
  5. # feature needed for +( ) to work; in older bash releases, even needed in PEs
  6. shopt -s extglob
  7.  
  8. parentDirTgt=foo # the thing you were grepping for in original code
  9.  
  10. errors_seen=0
  11. while IFS=/ read -r parentDir subDir rest <&3; do
  12. parentDir=${parentDir##+([[:space:]])} # strip leading whitespace
  13. [[ $parentDir = $parentDirTgt ]] || continue
  14. file=$parentDir/$subDir/$rest
  15. case $subDir in
  16. bar1) func1 "$file";;
  17. *) echo "Ignoring change in unrecognized subdirectory $subDir" >&2
  18. errors_seen=1;;
  19. esac
  20. done 3<&0 #<(git diff --diff-filter=dr --name-only origin/main..."$My_branch")
  21.  
  22. exit "$errors_seen"
  23.  
Success #stdin #stdout #stderr 0.01s 5572KB
stdin
  foo/bar1/file1.json
  foo/bar1/file2.json
stdout
func1 was in fact run for: foo/bar1/file1.json
func1 was in fact run for: foo/bar1/file2.json
stderr
+ shopt -s extglob
+ parentDirTgt=foo
+ errors_seen=0
+ IFS=/
+ read -r parentDir subDir rest
+ parentDir=foo
+ [[ foo = foo ]]
+ file=foo/bar1/file1.json
+ case $subDir in
+ func1 foo/bar1/file1.json
+ echo 'func1 was in fact run for: foo/bar1/file1.json'
+ IFS=/
+ read -r parentDir subDir rest
+ parentDir=foo
+ [[ foo = foo ]]
+ file=foo/bar1/file2.json
+ case $subDir in
+ func1 foo/bar1/file2.json
+ echo 'func1 was in fact run for: foo/bar1/file2.json'
+ IFS=/
+ read -r parentDir subDir rest
+ exit 0