Results 1 to 2 of 2
Hi, I am doing a script in tcsh (yes I know, I know..) and I have suddenly bumped into a problem I'm pretty sure I hadn't experienced up to now..
...
- 05-12-2011 #1Just Joined!
- Join Date
- May 2011
- Posts
- 2
extra characters when using `ls *.*` in loops
Hi, I am doing a script in tcsh (yes I know, I know..) and I have suddenly bumped into a problem I'm pretty sure I hadn't experienced up to now..
For various reasons I find the following type of loop very useful for my purposes:
now, if I echo the variable to a file (i.e., echo $m >> test.txt) I can see that it's adding plenty extra characters plus a new line. Needless to say it jumbles up the "something based on $m" commands.Code:foreach m (`ls folder/*.*`) echo $m something based on $m something else based on $m end
To give you an example, I have a folder (ROIs) with the following files in it
if I run the above loop echoing the $m variable to a file, and then `less` the file, here is what I get:Code:ROIs/csf_segm2func.nii.gz ROIs/csf_segm.nii.gz ROIs/gm_segm2func.nii.gz ROIs/gm_segm.nii.gz ROIs/wm_segm2func.nii.gz ROIs/wm_segm.nii.gz
In fairness, I use this sort of syntax real often and it's the first time it gives me this problem.Code:ESC[0mESC[01;31mROIs/csf_segm2func.nii.gzESC[0m ESC[01;31mROIs/csf_segm.nii.gzESC[0m ESC[01;31mROIs/gm_segm2func.nii.gzESC[0m ESC[01;31mROIs/gm_segm.nii.gzESC[0m ESC[01;31mROIs/wm_segm2func.nii.gzESC[0m ESC[01;31mROIs/wm_segm.nii.gzESC[0m ESC[m test.txt (END)
Any clues??
thank you
MCube
- 05-13-2011 #2Just Joined!
- Join Date
- Apr 2011
- Posts
- 19
unalias
I suspect you have an alias for ls to turn on color display. You may want to unalias it before using.
Also, why not just do
foreach m (folder/*) ...
not sure why your using ls.


Reply With Quote