如何在脚本中保存行号?

时间:2018-05-18 18:21:05

标签: powershell-core

尝试告诉脚本将行号保存为变量。

在Windows Powershell中运行良好,如果我手动将其放入PS Core。

    $num = Select-String source.txt -pattern "XXXXX" | Select-Object -Expandproperty LineNumber

但是运行一个调用另一个脚本的PS Core的脚本,那个位对我来说不起作用。 “Get-Variable”返回空白。

编辑:在PowerShell-6.1.0-preview.2中

还在1个脚本中尝试了所有内容,以确认它与行号不一致。

$path = split-path -parent $MyInvocation.MyCommand.Definition
cd $path
$mc = "1.12.2"
$mv = $mc
$mod = "armor-chroma"
$client = new-object System.Net.WebClient
$mod = "https://minecraft.curseforge.com/projects/$mod/files"
$client.DownloadFile("$mod/files","$path\source.txt")
$num = Select-String source.txt -pattern "  $mv</option>" | Select-Object -Expandproperty LineNumber
Get-Variable num
pause

再次,使用copy&amp; paste(手动设置$ path),但是当我使用PowerShell Core运行.ps1时,“Get-Variable num”返回空白。

0 个答案:

没有答案