![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read list of filenames from text file and remove these files in multiple directories | fxvisions | Shell Programming and Scripting | 5 | 08-07-2008 12:59 PM |
| How to delete multiple space or tabs from a read only file | bisla.yogender | Shell Programming and Scripting | 6 | 05-14-2008 04:38 AM |
| how can I read the space in the end of line | Ehab | UNIX for Advanced & Expert Users | 2 | 09-30-2007 07:13 AM |
| read list of filenames from text file, archive, and remove | fxvisions | Shell Programming and Scripting | 5 | 03-20-2007 06:56 PM |
| How to keep white space is being deleted using read | keelba | Shell Programming and Scripting | 1 | 05-30-2002 11:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I need to read filenames with space in between in a for loop like Integration of utility projects Integration of hdf projects I copied these files from a windows system and as you know windows filename has spaces in between them. But while unix is reading the filename in a for loop it reads word by word and in the end it's futile because all the filenames has space in between. This is the command I use to read the filenames for i in `ls -l` Is there a way to accomplish this. Please help me on this. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
try
Code:
ls -1 | while read filename do echo "$filename" done |
|
#3
|
|||
|
|||
|
Thanks a lot.
It worked fine. Can you please explain why is this not possible in a for loop instead of a while loop? What makes the difference. |
|
#4
|
||||
|
||||
|
Hi,
There is no reason that it doesn't work with for loop, try this: Code:
for i in "`ls -1`" do echo "$i" done |
|
#5
|
|||
|
|||
|
you could also set the internal-field-seperator to a newline, if you use bash
IFS=" " check man bash /IFS |
|
#6
|
||||
|
||||
|
Notice that the solution is 'ls -1' (one, not "el"). That puts each file on it's own line. When you read it, you're assigning the whole line to a variable, not per whitespace-delimited word.
|
|
#7
|
||||
|
||||
|
Quote:
|
||||
| Google The UNIX and Linux Forums |