Problem with blank spaces in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with blank spaces in shell script
# 1  
Old 05-07-2010
Question Problem with blank spaces in shell script

Hi,

I did the following script:
Code:
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.
# 2  
Old 05-07-2010
Try quoting $DIR and $i.

$DIR --> "$DIR"
$i --> "$i"
# 3  
Old 05-07-2010
Code:
for i in $(find . -name GESTION -type d)
do
  (
    cd "$i/.."
    setfacl -R -m g:directores:rwx GESTION
  )
  echo $PWD/$i
done

# 4  
Old 05-07-2010
Bug

Thank you very much for all your answers!!

The final code is this:

Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Problem with shell script while spaces encountered in directory names

Hi, I am having issues with the jar -tf command when I put in the shell script. The command runs fine from the command line as shown below. # jar -tf "./VirtualBox Dropped Files/2016-04-17T20:58:49.129139000Z/hive-exec-0.8.1.jar" But when I put in a shell script(shown below) and the... (10 Replies)
Discussion started by: vinoo128
10 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. Shell Programming and Scripting

Remove blank spaces

Gents, Please can you help me.. to remove blank spaces :) Input ABSOLUTE , ,FALSE ,1035 ,28 ,669 ,1817.0 ,CORREL BEFORE ,1 ABSOLUTE , ,FALSE ,1035 ,28 ,686 ,1817.0 ,CORREL BEFORE ,1 ABSOLUTE , ,FALSE ,1035 ,28 ,670 ,1819.0 ,CORREL BEFORE ,1 ABSOLUTE , ,FALSE ... (4 Replies)
Discussion started by: jiam912
4 Replies

4. Solaris

Removing blank spaces

Hi , I want to go out of vi editor temporarily and execute a command in command prompt and again going back to the editor . Is it possible . Any help on this is really helpful. 1. Need to open vi 2. Temporarily come out and execute a command and go back to vi editor (6 Replies)
Discussion started by: rogerben
6 Replies

5. Shell Programming and Scripting

removing blank spaces in a script

Hi I am writing a shell to run sqlplus scripts. i found a issue in my scripts that oracle will not spool a file if there is blank spaces in the word like /backup dir/scriptrelease/1_DDL or /backupdir/script release/2_DDL can we write some thing in the shell to make "/backup dir" to... (1 Reply)
Discussion started by: srichunduru
1 Replies

6. Shell Programming and Scripting

Problems with Blank Spaces

Hi to all. How can I pass to the stat command a file path with blank spaces? And another question, if I use stat command like this: stat / -name "*.sh" -user $user_name -exec stat -c %n%x {} \; How can I get the result with a ":" into the name of the file and the time of the last... (4 Replies)
Discussion started by: daniel.gbaena
4 Replies

7. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

8. Shell Programming and Scripting

Handling blank spaces

Hi, I am trying to replace a specific column values in a csv file with double quotes when I am find embedded spaces with in the fields. Example: SNO,NAME,ZIPCODE,RANK,SEX,ADDRESS 1,Robert,74538,12,34, M,Robert Street, NY 2,Sam,07564,13,M,12 Main Ave, CA 3,Kim, Ed,12345,14,M,123D ,... (1 Reply)
Discussion started by: techmoris
1 Replies

9. UNIX for Dummies Questions & Answers

string with blank spaces

I have a file that has dates like this: date FINAL_RESULT; 7 date FINAL_RESULT; 2 date FINAL_RESULT; 5 With this command: seira=`cut -f2 -d\; tes.txt` i take the date FINAL RESULTs and i store them on variable seira.then seira look like this: 6 3 8 I want to read seira and make a sum of all... (4 Replies)
Discussion started by: psalas
4 Replies

10. UNIX for Dummies Questions & Answers

problem with the blank spaces in array

Hi all! i need your help. I'm getting started with this... in need to insert in an array string values. But the thing is that this strings have blank spaces... for example if a want to put "filed1 = " and "field2 = " .... in the array , when i want to print all the fields, it only shows... (4 Replies)
Discussion started by: kamicasse
4 Replies
Login or Register to Ask a Question