file name spaces problem
Hi,
im trying to list the contents of directory that has files with space in their filename. my directory: (with ls -b) 01\ -\ Tear\ Me\ Down.mp3 08\ -\ Exquisite\ Corpse.mp3 02\ -\ The\ Origin\ of\ Love.mp3 09\ -\ Midnight\ Radio.mp3 03\ -\ Angry\ inch.mp3 10\ -\ Nailed.mp3 .... the command i am running #!/bin/tcsh -f set pw=`pwd` foreach fn ( `ls | add_quotes`) printf "%s/%s\n",$pw,$fn end the output i am getting: ,/mnt/wind/Media/Music/Soundtracks/Hedwigangry/inch,"01 ,/mnt/wind/Media/Music/Soundtracks/Hedwigand/the ,/mnt/wind/Media/Music/Soundtracks/Hedwigangry/inch,- ,/mnt/wind/Media/Music/Soundtracks/Hedwigand/the ,/mnt/wind/Media/Music/Soundtracks/Hedwigangry/inch,Tear . . . As you can see, it is splitting the filename in the space although i do use the "\" (ls with -b) Anyone???!?!?!? :confused: :confused: :confused: |
How about something like this...
Code:
#!/bin/bash |
Re: file name spaces problem
Hi hesher,
Came across your post while looking for clues on how to solve a similar problem. Didn't find any good clues, so I thought "let's RTFM...". :cry: And behold...:D: Here's how to do it in tcsh: Code:
#!/bin/tcsh -f Normally, tcsh breaks the output of command substitution ( i.e. `...` ) into 'words' (components of variables) at spaces and newlines. The breaks at spaces are suppressed if you enclose the command substitution in double quotes. So even though it looks weird, and you'd expect the loop to execute only once, it does works grace to the newlines produced by "ls -1" (BTW, that's the DIGIT 1; not the letter l...). And you need to quote $pw and $fn too, or you may still get rubbish. |
All times are GMT -5. The time now is 07:15 AM. |