Linux 未设置 TERM 环境变量上的 Powershell v2.0

Powershell v2.0 on Linux TERM environment variable not set

我是 运行 Powershell v2.* on VSTS Hosted Ubuntu 1604

我得到 未设置 TERM 环境变量。

这是我的代码。非常感谢任何想法。

$env:TERM="xterm"

function Update-Tokens()
{
    param(
        [Parameter(Mandatory=$true)][string]$filePath,
        [Parameter(Mandatory=$true)][string]$tokensStartingWith
    )

    Write-Host -Fore Yellow "Replacing Tokens";

    $fileContents = [IO.File]::ReadAllText($filePath)


    foreach($theEnv in (Get-ChildItem env:* | sort-object Name)){
        if($theEnv.Name.StartsWith($tokensStartingWith))
        {
            Write-Host -Fore Yellow "Updating: $($theEnv.Name)=$($theEnv.Value)"
            $fileContents = $fileContents.Replace("`${$($theEnv.Name)}", $theEnv.Value)
        }
    }

    $fileContents | Out-File -Encoding utf8 -filePath $filePath | Out-Null
    Write-Host -Fore Yellow $fileContents

}
cls
Update-Tokens -filePath "./azure-support-ticket-k8s.yaml"-tokensStartingWith "SUPPORT_TICKET_BUILD_" | Out-Null

答案是去掉cls语句! 此外,您不需要 $env:TERM="xterm" 语句(将其删除)。 这在 Windows 托管代理上没有问题,但在 Linux 上失败了。当 运行 非交互式脚本时,与终端无法清除屏幕有关。