powershell - 为什么 PowerShell 中的变量扩展为 `-encodedCommand` 而不是其实际值?

标签 powershell

我希望 $mydate 变量或命令 Get-Date -Format yyyy-MM-dd 在以下命令行中展开(注意 curly braces required by the svn.exe client :

$mydate = Get-Date -Format yyyy-MM-dd

svn log https://svn.apache.org/repos/asf/ -r {Get-Date -Format yyyy-MM-dd}

svn log https://svn.apache.org/repos/asf/ -r {$mydate}

在这两种情况下,我都会收到以下错误:

svn: E205000: Syntax error in revision argument '-encodedCommand'

为什么变量变成了-encodedCommand?我应该逃避大括号吗?如何?勾选 '`' 不起作用:

Error formatting a string: Input string was not in a correct format..
At line:1 char:1
+ svn log https://svn.apache.org/repos/asf/ -r `{$mydate`}

我做错了什么?

最佳答案

我没有足够的分数来发表评论,但请尝试:

svn 日志 https://svn.apache.org/repos/asf/-r "{$($mydate)}"

外面的 "引号将它全部转换为字符串,因此忽略大括号。$() 允许正确解释变量(而不是字符串)。

关于powershell - 为什么 PowerShell 中的变量扩展为 `-encodedCommand` 而不是其实际值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52721768/

相关文章:

某些 JSON 文件出现 PowerShell FilterScript 错误

powershell - 在 PowerShell 中使用 --%

excel - 如何使用 Powershell 在 Excel 文件中进行区分大小写的查找和替换

powershell - FTP上传文件时出错

powershell - 如何在 Azure DevOps 上的 Windows 管道中为 Go 生成 syso 文件

PowerShell 对多个参数进行过滤

powershell - 使用PowerShell从文本文件中删除空行

windows - 使用未执行的预定义命令运行 Windows 终端

Powershell DSC : Unable to load module xPSDesiredStateConfiguration

windows - 在所有子目录中调用 git init 的 Powershell 脚本