Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spaces in path names giving trouble with Find in Bash. Any *simple* work-around?

Tags:

find

bash

Is there any way to change the following string so I don't get any problems when there are files/folders with spaces in them?

files=`find ~/$folder -name "*@*" -type f`

I'd prefer if there was a solution that wouldn't have to involve having to change other parts of my code but this line of code, as everything seems to be working correctly, apart from this minor detail.

Thanks

EDIT: Here is the code in a bit more detail:

abc=( $(find "$pasta" -name "$ficheiro_original@*" -type f) )
abc_length=${#abc[@]}
like image 904
devoured elysium Avatar asked Oct 10 '10 01:10

devoured elysium


1 Answers

If you are not using those file names later in your script , just iterate them and process on the fly.

find ~/$folder -name "*@*" -type f | while read -r FILE
do
  echo "do you stuff"
done

otherwise, you can set IFS

IFS=$'\n'
files=$(find ~/$folder -name "*@*" -type f)

Update:

$ IFS=$'\n'
$ a=($(find . -type f ))
$ echo ${#a[@]}
14
like image 88
ghostdog74 Avatar answered Nov 21 '22 06:11

ghostdog74