LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-06-2005, 04:33 AM   #1
rvoigt
LQ Newbie
 
Registered: Mar 2004
Location: Sydney
Posts: 17

Rep: Reputation: 0
Handling whitespace in For loop


Hi there

I'm trying to write a script that will list all files and directoryfrom a directory.


LIST=$(ls $DIRNAME)

for file in $DIRNAME; do

echo $file

done.

Unfortunately the for loop does not handle whitespaces in files.

Is there a solution to it?

Is there a system variable that define the field separator of a for loop?

Thank you.
 
Old 04-06-2005, 06:57 AM   #2
sandipan
Newbie
 
Registered: Mar 2005
Location: India
Distribution: Red Hat Linux 8.0
Posts: 5

Rep: Reputation: 0
wat is it that u want to do ? just print them? then u can change IFS,like

IFS='\n' before that code will work.

else try

for file in "`ls $DIRNAME`";do
echo $file
done

note that though this will print files you can't perform any action on files indivdually . thats because the whole thing is put infile in 1 go....
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Proper whitespace formatting on stdout R00ts Programming 5 07-30-2005 04:27 PM
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 02:22 PM
problem creating BASH script with files that have whitespace scattaneo Linux - General 2 11-06-2004 05:40 PM
remove whitespace at end of file FunkyRes Programming 2 10-05-2004 12:31 AM
Using sed in bash to remove whitespace jimieee Programming 3 01-28-2004 10:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:42 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