home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10064 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.2 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rphroy!ilium!sycom!curlie!thierry
  2. From: thierry@curlie.UUCP (Thierry Lach   )
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: csh foreach question
  5. Keywords: csh,foreach
  6. Message-ID: <wX3gPB3w164w@curlie.UUCP>
  7. Date: 14 Aug 92 01:21:07 GMT
  8. References: <BswB6M.Dxw@news.cso.uiuc.edu>
  9. Organization: Not An Organization
  10. Lines: 39
  11.  
  12. gordon@osiris.cso.uiuc.edu (John Gordon) writes:
  13.  
  14. >     Given the following script:
  15. > #
  16. > foreach line ( `cat this_script` )
  17. >   echo "$line"
  18. > end
  19. >     I would expect the output to be:
  20. > #
  21. > foreach line ( `cat this_script` )
  22. >   echo "$line"
  23. > end
  24. >     However, I get:
  25. > #
  26. > foreach
  27. > line
  28. > (
  29. > )
  30. > echo
  31. > "$line"
  32. > end
  33. >     Is this what's supposed to happen?  Any help appreciated.
  34. > ---
  35. > John Gordon                        My incredibly witty saying has been 
  36. > gordon@osiris.cso.uiuc.edu         Politically Corrected into oblivion.
  37.  
  38. Yes.  The `cat this_script` will take each token (as recognized
  39. by the shell, meaning anything delimited by whitespace), and
  40. make it an argument to the foreach.  Because newline is whitespace,
  41. they are not maintained, and because the echo does not override
  42. the newline, you get one token per line.
  43.