In linux shell scripting I am trying to set the output of find into an array as below
#!/bin/bash arr=($(find . -type -f))
but it give error as -type should contain only one character. can anybody tell me where is the issue.
Thanks
If you are using bash
4, the readarray
command can be used along with process substitution.
readarray -t arr < <(find . -type f)
Properly supporting all file names, including those that contain newlines, requires a bit more work, along with a version of find
that supports -print0
:
while read -d '' -r; do
arr+=( "$REPLY" )
done < <(find . -type f -print0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With