这个问题在这里已有答案:
什么是CMD的等效声明:
dir && cd ..
在Powershell?
我试过了:
dir -and cd ..
但它会引发错误:
Get-ChildItem:找不到与参数名称'和'匹配的参数 . 在行:1 char:5 dir - 和(cd ..)CategoryInfo:InvalidArgument:(:) [Get-ChildItem],ParameterBindingException FullyQualifiedErrorId:NamedParameterNotFound,Microsoft.PowerShell .Commands.GetChildItemCommand
2 回答
在PowerShell中没有直接等效的cmd.exe && 这意味着"only execute right-hand side if the left-hand side succeeds."但是你可以写一个简短的函数来做同等的事情:
例如:
如果你想让$ testExpression产生输出,那么IfTrue函数可以写成如下:
法案
这个怎么样?
正在运行
get-help about_automatic_variables | more
解释:在PS中,
dir
只是get-ChildItem
的别名;cd
同样适用于Set-Location
.edit: 同样的问题here,包括an answer直接从马的嘴里 .