LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cygwin and space issue in a script. (https://www.linuxquestions.org/questions/programming-9/cygwin-and-space-issue-in-a-script-589603/)

angel115 10-05-2007 04:22 AM

Cygwin and space issue in a script.
 
Hello there,

I have an issue with spaces in the path of the files.

Here is the issue:
Code:

#! /bin/bash
date=$( date +%y_%m_%d_ )

for filetodelete in $( cat c:/Program\ Files/Serv-U/HouseKeeping/log/${date}file_to_delete.txt  ); do

 /usr/bin/echo "${filetodelete}"
 # The last action will be "rm -f" intead of "echo"
 
done


and the file "07_10_05_file_to_delete.txt" is look like:
Code:

/cygdrive/f/FTPRoot/dropbox/log.zip
/cygdrive/f/FTPRoot/dropbox/report-20070911.zip
/cygdrive/f/FTPRoot/dropbox/Issues with Server.txt

but when I run this script each time it meet a " " it echo the rest of the line on a new line which is giving me some thing like this:
Code:

/cygdrive/f/FTPRoot/dropbox/log.zip
/cygdrive/f/FTPRoot/dropbox/report-20070911.zip
/cygdrive/f/FTPRoot/dropbox/Issues
with
Server.txt

How to prevent the space to be taken as a new line?

Regards,

ghostdog74 10-05-2007 09:14 PM

use while loop
Code:

while read line; do echo "$line"; done < file

carl.waldbieser 10-05-2007 09:27 PM

The reason you are getting this behavior is because $(...) takes the output of its pipeline and replaces all the word separators (e.g. spaces, tabs, newlines) with single spaces. Your for loop iterates over each new word in the list.

To make this a little clearer:
Code:

$ echo $(echo one; echo two;)
one two

Notice that the output is on a single line. That is because the command evaluates to:
Code:

$ echo one two

chrism01 10-07-2007 11:14 PM

You could set the IFS to newline only at the top of your script; by default it's any of space/tab/newline.

angel115 05-22-2008 07:43 AM

Case SOLVED :D
 
Hi Chrism01,

Yes, you're right, after adding the "IFS=$'\n'" line at the begining of my script it's working fine now.

Thank you for your help.

Regards,
Angel.


All times are GMT -5. The time now is 02:21 AM.