How to use foreach on filenames with spaces?
say I have some file names with spaces, like so:
$ ls New Text Document (2).txt New Text Document.txt (there are two files there) and I want to loop over them and do something to them in a foreach loop, like so: $ foreach f ( `find . -name \* -print0` ) foreach? echo $f foreach? end ./New Text Document.txt ./New Text Document (2).txt obviously, that's not the output I want, I need to get the actual file name as opposed to their bits so I can do something to the file. Is there a way to do this? I'm using tcsh Thanks |
Have you considered:
Code:
find . -print0 | xargs -0 THECOMMANDTOEXEC |
just before issuing the command set IFS='\t\n'
after the command re-set it to ' \t\n' (a space as first character) this results in bash not recognizing spaces as word separators. It remains a problem if the command you execute relies on that. |
You can't set IFS to ' \t\n'. For some silly reason, it doesn't expand escaped characters in it, you must set them as literals. So do "IFS='<space><tab><newline>'"
|
All times are GMT -5. The time now is 01:51 AM. |