LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   space in file name Error (https://www.linuxquestions.org/questions/linux-newbie-8/space-in-file-name-error-4175434941/)

vicky007aggrwal 10-31-2012 01:33 PM

space in file name Error
 
Can someone please suggest how to print out the names of files having space in between them.

I am running the following for loop , but the thing is it is treating space delimiter between file names as new file ......please help

*************************************************

>>>>>>>>>ls -lrt
total 0
-rw-r--r--. 1 root root 0 Oct 31 11:31 file 3
-rw-r--r--. 1 root root 0 Oct 31 11:31 file 2
-rw-r--r--. 1 root root 0 Oct 31 11:31 file 1

>>>>>for i in `ls`; do echo $i;echo "****"; done
file
****
1
****
file
****
2
****
file
****
3
****

unSpawn 10-31-2012 01:47 PM

In a previous thread it was suggested to prefer "while" over "for" loops. See if you can deal with things using:
Code:

find /path/ type f -iname file\* | while read ITEM; do
 doSomething "${ITEM}"
..


* In previous threads you have also been made aware of mywiki.wooledge.org and the Advanced Bash Scripting Guide. I'm going to add a few links in the hope you read and consult them:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.gnu.org/software/bash/man...ode/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls

vicky007aggrwal 10-31-2012 01:54 PM

???????????

unSpawn 10-31-2012 01:57 PM

Also mark your own threads you replied to today as "solved" if they are and don't post this kind of "????" nonsense.

vicky007aggrwal 10-31-2012 02:02 PM

Thankz for ur heartfelt comments .. I didnt understand that y written ?..

unSpawn 10-31-2012 03:08 PM

Quote:

Originally Posted by vicky007aggrwal (Post 4819129)
for i in `ls`; do echo $i;echo "****"; done

Code:

find /path/ type f -iname file\* | while read ITEM; do echo "${ITEM}"; echo "****"; done


All times are GMT -5. The time now is 07:24 AM.