Make an array of files you find

/ Published in: Bash
Save to your folder(s)

Copy this code and paste it in your HTML
  1. # Requires GNU find (for -print0). Since the find example starts in ".", I replace
  2. # the leading "./" of all results with the working directory PWD to get an absolute
  3. # path for each result. Alternatively use 'find "$PWD"' instead of 'find .'
  4. unset a
  5. declare -a a
  6. while read -d '' -r; do
  7. a+=("$PWD/${REPLY#./}")
  8. done < <(find . -name \*.txt -print0)
  9. # Verify
  10. printf ">%s<\n" "${a[@]}"
  12. # Same, on one line, without the, using "$PWD" and without GNU find:
  13. unset a; declare -a a; while read -d '' -r; do a+=("$REPLY"); done < <(find "$PWD" -name \*.txt -exec printf "%s\0" {} \;)

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.