LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2007, 04:22 AM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Rep: Reputation: 79
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,
 
Old 10-05-2007, 09:14 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
use while loop
Code:
while read line; do echo "$line"; done < file
 
Old 10-05-2007, 09:27 PM   #3
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
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
 
Old 10-07-2007, 11:14 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You could set the IFS to newline only at the top of your script; by default it's any of space/tab/newline.
 
Old 05-22-2008, 07:43 AM   #5
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
Thumbs up 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.

Last edited by angel115; 06-02-2008 at 04:15 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help updating imagemagick on cygwin to run script babag Programming 1 01-25-2007 12:04 PM
Disk Space Issue nbjayme Linux - General 5 02-21-2004 07:25 AM
Disk Space Issue. jesterwhite Linux - General 3 03-08-2003 11:41 AM
Mandrake 8.1 disk space management issue lhoff Linux - Distributions 5 11-21-2002 09:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration