csh - foreach random no match -


this code:

set source_failed = `cat mine.log`  set dest_failed = `cat their.log`  foreach t ($source_failed)   set isdiff = 0   set sflag = 0   foreach t2 ($dest_failed)     if ($t2 == $t)       set sflag = 1       break     endif   end   ... end 

problem inner foreach loop runs okay first few 10 iterations. after iteration, got

foreach: no match 

moreover, iterating on array of strings, not files. reason behind error?

the problem (probably) mine.log and/or their.log contain special globbing characters, such * or ?. shell try expand file. there no matches accidental pattern, , hence error "no match".

the easiest way prevent behaviour add set noglob top. tcsh(1):

    noglob  if set, filename substitution , directory stack  substitution            (q.v.)   inhibited.    useful in shell scripts            not deal filenames, or after list of  filenames            has been obtained , further expansions not desirable. 

you can re-enable behaviour using set glob.

alternativly, can use :q. tcsh(1):

unless  enclosed in `"' or given `:q' modifier results of variable substitution may command ,  filename  substituted.  [..]  when `:q' modifier applied substitution variable expand multiple words  each  word  sepa rated   blank , quoted prevent later command or filename sub stitution. 

but need careful quoting when use variable. in below example, echo command fail if don't add quotes (set noglob easier):

set source_failed = `cat source`  foreach t ($source_failed:q)     echo "$t" end 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -