0

我试图按照在线教程进行操作,并想知道为什么他们不必".\"在 shell 中使用。发现这个$env:PATH =$env:PATH+";."我试过了,但现在我想回到原来的样子。我试过手动查看路径,而且我是 powershell 新手。我将如何在 shell 中删除我的路径?

4

2 回答 2

0

您可以使用-replace运算符将​​其替换为字符串中的任何位置:

$env:PATH = $env:PATH -replace '\.\\?;|;\.\\?$',''
于 2013-11-14T14:25:47.037 回答
0

我不知道这是否是最好的方法,但你可以这样做。例如,要禁止您添加的最后一条路径:

# Do an array with all paths
$currpath = $env:PATH.Split(";")

# Suppress the last path in the array
$newpath = $currpath[0..($currpath.Count -2)]

# Convert array into string and re-add it in the $env:PATH
$env:PATH = $newpath | % { $temp += $_ + ";" }
于 2013-11-14T10:19:37.710 回答