'How to store line by line in a variable?

I want to search for hidden directories or files with "find" and store it in a variable. I tried like this and it works, but it is stored one after one in TEST. How can i store it line by line?

TEST=$(find /home -name ".*")
echo $TEST

Thank you!



Solution 1:[1]

The result of find are many lines.

So suggest to read find output into array.

 readarray -t arr <<< $(find /home -name ".*")
 # print all elements in array arr
 printf "%s\n" "${arr[@]}"
 # print first element in array arr
 echo "${arr[0]}"
 # print second element in array arr
 echo "${arr[2]}"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dudi Boy