简体   繁体   中英

Linux FIND searching files with names within single quotes

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM