【问题标题】:[System.IO.File]::WriteAllLines adds newline at the end[System.IO.File]::WriteAllLines 在末尾添加换行符
【发布时间】:2012-10-30 09:13:50
【问题描述】:

我有这个代码:

# Generate bash script
$bashScript = "#!/bin/bash`n";
$bashScript += [string]::Join("`n", $cmds)

[System.IO.File]::WriteAllLines($location.ToString() + ".\build.sh", $bashScript);

问题是我总是在文件末尾得到CRLF 字符!

#!/bin/bash [LF]
tsc ... [LF]
java ... [LF]
java ... [CR][LF]

除了最后替换CRLF,我还能做些什么吗?

【问题讨论】:

    标签: file shell powershell newline


    【解决方案1】:

    我不会说 Powershell,但在我看来,您似乎告诉它写一个大行 ($bash_script),末尾有一个换行符 (CRLF)。请致电WriteAllText。确保文件末尾有一个 LF。

    $bashScript = "#!/bin/bash`n" + [string]::Join("`n", $cmds) + "`n"
    [System.IO.File]::WriteAllText($location.ToString() + ".\build.sh", $bashScript);
    

    【讨论】:

      猜你喜欢
      • 2014-05-28
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-26
      • 1970-01-01
      • 2017-04-28
      • 1970-01-01
      • 2014-07-10
      相关资源
      最近更新 更多