LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-15-2003, 03:18 PM   #1
ken734
LQ Newbie
 
Registered: Aug 2003
Posts: 5

Rep: Reputation: 0
display full line instead of single word in for loop


I am brand new to linux, and trying to do a few things with scripts. My question is in using a for loop, how I can get it to display a full line instead of a single word. For example:

for file in `ls -l`:do
echo $file
done

If anyone knows how to get the $file variable to display a full line instead of a single word I would greatly appreciate it.
 
Old 08-15-2003, 03:20 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Set the field seperator to a newline before the loop:
IFS="
"
for file in `ls -l`;do
echo $file
done
 
Old 08-15-2003, 03:29 PM   #3
ken734
LQ Newbie
 
Registered: Aug 2003
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks!!!

Thanks a bunch.

I am too embarrassed to tell you how much time I wasted trying to get that result.

Thanks again!
 
Old 08-15-2003, 03:35 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Re: Thanks!!!

Quote:
Originally posted by ken734
Thanks a bunch.

I am too embarrassed to tell you how much time I wasted trying to get that result.

Thanks again!
No problem - took me a while the first time too
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
add word to each line of the file? ziggie216 Linux - General 4 04-25-2005 05:19 AM
Loop line by line script twantrd Programming 7 01-17-2005 12:47 AM
help... get single word from file night-blade1 Programming 3 10-12-2004 09:58 AM
word count in a line pantera Programming 4 08-25-2004 02:14 PM
How do I load with a single hardrive full with XP barrys Fedora 10 01-26-2004 11:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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