1

I am trying to save results of FIND command into array so then I can do some AWK commands with them.

My actual code is: files_arr=( "$(find "$1" -type f \( -name "\'*[[:space:]]*\'" -o -name "*" \) -perm -a=r -print )

  • this code should find all files with spaces and without spaces and return them to my array (and are readable also)

The PROBLEM is, when I have directory named: 'not easy' and inside this is directory are files: 'file one' and 'file two'
so what I will get is: not easy/file one
what I want to get is: 'not easy'/'file one'

I was thinking about using SED to add quotes but it would add quotes even if I had just simple one word file which doesnt have quotes in it.
Thank you for our advices.

Thomas99
  • 9
  • 2

1 Answers1

1

Try this out :

mapfile -d '' files_arr < <(find . -type f -name "'*[[:space:]]*'" -perm -a=r -print0)
declare -p files_arr # To see what's in the array
Philippe
  • 20,025
  • 2
  • 23
  • 32
  • thank you sir, this helped me a lot, it works. FINAL CODE IS: ```mapfile -d '' files_arr < <(find "$1" -type f \( -name "\'*[[:space:]]*\'" -o -name "*" \) -perm -a=r -print0)``` This find all files, normal and also those with special characters in it. – Thomas99 Dec 06 '21 at 10:35