1

I'm trying to save the find output to a variable in this manner:

a=find /Users/Downloads/DTI_allsites/subprojects/*/UII_0077 -name "dti_preprocessed" -type d

But I keep getting the following message:

-bash:

/Users/Downloads/DTI_allsites/subprojects/UII_B/UII_0077: is a directory

whenever I try to use the command, to echo the path using: echo $a

I don't get anything saved in the variable. How can I fix this?

hsayya
  • 21
  • 1
  • 6

1 Answers1

1

Since find returns a list of file paths, you'd want to use an array variable. Since a file path can contain any character but NUL, you'd want to use -print0 and split the result on NUL

With bash4.4+:

readarray -td '' list < <(find ... -print0)

so-something-with "${list[@]}"