Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 04-06-2005, 04:33 AM   #1
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.


for file in $DIRNAME; do

echo $file


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
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

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....


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:46 AM.

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