Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

powershell is missing the terminator: "

I have the following script code

    #[string]$password = $( Read-Host "Input password, please" )
    param (
        [string]$ReleaseFile = $(throw "-ReleaseFile is required"),
        [string]$Destination = $(throw "-Destination is required")
    )

    function unzipRelease($src, $dst)
    {
        $shell = new-object -com shell.application
        $zip = $shell.NameSpace($src)
        foreach($item in $zip.items())
        {
            $shell.Namespace($dst).copyhere($item)
        }
    }

    #  .deployrelease.ps1 -ReleaseFile ".deploy.zip" -Destination "."

    unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

I run the script with: .deployrelease.ps1 -ReleaseFile ".deploy.zip" -Destination "."

But I keep getting this:

    PS C:UsersAdministratorDocumentsTools> .deployrelease.ps1 -ReleaseFile ".deploy.zip" -Destination
    The string starting:
    At C:UsersAdministratorDocumentsToolsdeployrelease.ps1:19 char:16
    + unzipRelease a? <<<< "Src '$ReleaseFile' -Dst '$Destination'
    is missing the terminator: ".
    At C:UsersAdministratorDocumentsToolsdeployrelease.ps1:19 char:55
    + unzipRelease a?"Src '$ReleaseFile' -Dst '$Destination' <<<<
        + CategoryInfo          : ParserError: (Src `'$ReleaseF...'$Destination`':String) [], ParseException
        + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

I couldn't find the fix as I do not see any problem.

Any help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Look closely at the two dashes in

unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

This first one is not a normal dash but an en-dash (&ndash; in HTML). Replace that with the dash found before Dst.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...