如何根据新行字符而不是csh中的空格来迭代变量中的每一行

时间:2016-12-02 06:46:27

标签: shell csh

#!/bin/csh -f

foreach line (`cat test.txt`)
  echo "$line"
end

test.txt文件包含以下内容:

  

如何提问

     

您对编程有疑问吗?

     

我们更喜欢可以回答的问题,而不仅仅是讨论过。

     

提供详细信息。分享您的研究。

     

如果您的问题与本网站有关,请在meta上询问。

但是在运行上面的 csh 脚本时,我得到的是以太空分隔符而不是新行打印的后续输出

./test.csh

输出位于文件enter image description here

1 个答案:

答案 0 :(得分:2)

你可以使用它;

#!/bin/csh -f
foreach line ( "`cat test.txt`" )
  echo $line
end

测试:

$ csh test.csh 
How to Ask
Is your question about programming
We prefer questions that can be answered, not just discussed.
Provide details. Share your research.
If your question is about this website, ask it on meta instead.
相关问题