LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   display full line instead of single word in for loop (https://www.linuxquestions.org/questions/linux-newbie-8/display-full-line-instead-of-single-word-in-for-loop-82327/)

ken734 08-15-2003 02:18 PM

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.

david_ross 08-15-2003 02:20 PM

Set the field seperator to a newline before the loop:
IFS="
"
for file in `ls -l`;do
echo $file
done

ken734 08-15-2003 02:29 PM

Thanks!!!
 
Thanks a bunch.

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

Thanks again!

david_ross 08-15-2003 02:35 PM

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


All times are GMT -5. The time now is 02:27 PM.