Problem with blank spaces in shell script

Hi,

I did the following script:

DIR=`pwd`;for i in `find . -name GESTION -type d`;do cd $i/..;setfacl -R -m g:directores:rwx,
GESTION;echo $DIR'/'$i;cd $DIR;done

This code do the following actions:

  1. Starting inside a folder, it's searching for any folder called "GESTION"
  2. Every time a folder called "GESTION" is found, then the script move to its parent folder, and then it applies ACL permissions to the folder GESTION by using the command setfacl.

The problem is that the script doesn't works when there was found a folder with a blank space in its name.
I mean:

/dir1/dir2/dir3/GESTION --> this works fine

/dir1/dir2/dir 3/GESTION --> this doesn't works
/dir1/dir2/dir3/2. GESTION --> this doesn't works

Thank you for your help.

Try quoting $DIR and $i.

$DIR --> "$DIR"
$i --> "$i"

for i in $(find . -name GESTION -type d)
do
  (
    cd "$i/.."
    setfacl -R -m g:directores:rwx GESTION
  )
  echo $PWD/$i
done

Thank you very much for all your answers!!

The final code is this:

oldIFS=$IFS;
IFS=$'\n'; 
WORD='7. GESTION'; 
LOG='/home/samba/logN04.txt';
DIR=$(pwd); 
for i in $(find . -name "$WORD" -type d);do 
   cd $i/..;setfacl -R -m g:calidad:rx $WORD; 
   echo $DIR'/'$i >> $LOG; 
   cd $DIR; 
done;
IFS=$oldIFS

and it's working fine.