在C#(不需要dos2unix)中创建linux shell脚本文件

在C#(不需要dos2unix)中创建linux shell脚本文件,c#,linux,shell,portability,eol,C#,Linux,Shell,Portability,Eol,我使用C#来创建shell脚本,以便在Linux中自动执行任务。 为此,我使用以下结构: List<string> batchFileLines = new List<string>(); batchFileLines.Add("shell command 1"); batchFileLines.Add("shell command 2"); System.IO.File.WriteAllLines(shellBatchFileName, batchFileLines.T

我使用C#来创建shell脚本,以便在Linux中自动执行任务。 为此,我使用以下结构:

List<string> batchFileLines = new List<string>();
batchFileLines.Add("shell command 1");
batchFileLines.Add("shell command 2");
System.IO.File.WriteAllLines(shellBatchFileName, batchFileLines.ToArray());
List batchFileLines=new List();
Add(“shell命令1”);
Add(“shell命令2”);
System.IO.File.writeAllines(shellBatchFileName,batchFileLines.ToArray());
但是,由于windows和linux()中的EOL差异,当我将文件移动到linux时,需要使用
dos2unix
命令更正shell文件中的EOL。 我想知道如何在C语言中操作我的文件,这样就不需要执行
dos2unix

用linux格式替换新行的方法是什么?

使用,我应该改变

System.IO.File.WriteAllLines(shellBatchFileName, batchFileLines.ToArray());


输出文件将不再需要
dos2unix

您可以在每行末尾附加ascii 10。@rory.ap DOS使用回车符和换行符(“\r\n”)作为行尾,Unix只使用换行符(“\n”)。因此我想我应该删除“\r”。可能重复的
System.IO.File.WriteAllText(shellBatchFileName, string.Join("\n", batchFileLines.ToArray()));