使用基于环境变量的路径运行脚本

时间:2018-11-30 18:43:52

标签: powershell syntax environment-variables

我将环境变量ARTEMIS_HOME设置为c:\artemis

PS C:\artemis_brokers> $env:ARTEMIS_HOME
C:\artemis

在此目录下,我有一个名为bin的文件夹,其中包含一个artemis.cmd脚本。如何使用系统变量在PowerShell中的任何位置运行此脚本?

我尝试以下操作均未成功:

PS C:\artemis_brokers> $env:ARTEMIS_HOME/bin/artemis
At line:1 char:19
+ $env:ARTEMIS_HOME/bin/artemis
+                   ~
You must provide a value expression following the '/' operator.
At line:1 char:19
+ $env:ARTEMIS_HOME/bin/artemis
+                   ~~~~~~~~~~~
Unexpected token 'bin/artemis' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression
PS C:\artemis_brokers> ./$env:ARTEMIS_HOME/bin/artemis
./$env:ARTEMIS_HOME/bin/artemis : The term './$env:ARTEMIS_HOME/bin/artemis'
is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ ./$env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> ./$env:ARTEMIS_HOME/bin/artemis.cmd
./$env:ARTEMIS_HOME/bin/artemis.cmd : The term './$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ ./$env:ARTEMIS_HOME/bin/artemis.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> ./"$env:ARTEMIS_HOME/bin/artemis.cmd"
./$env:ARTEMIS_HOME/bin/artemis.cmd : The term './$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ ./"$env:ARTEMIS_HOME/bin/artemis.cmd"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\$env:ARTEMIS_HOME/bin/artemis
.\$env:ARTEMIS_HOME/bin/artemis : The term '.\$env:ARTEMIS_HOME/bin/artemis'
is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ .\$env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\$env:ARTEMIS_HOME/bin/artemis.cmd
.\$env:ARTEMIS_HOME/bin/artemis.cmd : The term '.\$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ .\$env:ARTEMIS_HOME/bin/artemis.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\"$env:ARTEMIS_HOME/bin/artemis.cmd"
.\$env:ARTEMIS_HOME/bin/artemis.cmd : The term '.\$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ .\"$env:ARTEMIS_HOME/bin/artemis.cmd"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

2 个答案:

答案 0 :(得分:3)

在尝试执行之前,您需要扩展变量并将路径的其余部分连接为字符串。要执行结果字符串,请使用&the call operator

& "$env:ARTEMIS_HOME/bin/artemis.cmd"

答案 1 :(得分:1)

尝试:

foldl (-) 0 [1,2,3] == ((0 - 1) - 2) - 3 
                    == (-1 - 2) - 3 
                    == -3 - 3
                    == -6
foldr (-) 0 [1,2,3] == 1 - (2 - (3 - 0)) 
                    == 1 - (2 - 3)
                    == 1 - -1
                    == 2