powershell - 如何在 PowerShell 中使用 @ 字符

标签 powershell

我正在尝试执行以下操作 - 为当前目录中的每个 *.sql 文件运行

sqlplus username/password@connect_identifier_specified_in_argument @file_name

这是我目前所拥有的:

$scripts = dir *.sql
foreach($script in $scripts) {
    Write-Host sqlplus username/password"@"$args "@"$script.Name
}

(我知道 Write-Host 会将其输出到屏幕上;我现在只是尝试调试。)

然而,PowerShell 处理 @ 字符的方式有些奇怪,当我运行它时,我总是得到类似的东西:

PS C:\code\scripts> C:\utils\run_sql_scripts_on.ps1 identifier
sqlplus username/password@identifier @ ALERTS.sql

看到“@”后面的那个空格了吗?什么给了?

最佳答案

使用反引号 (`) 转义 @

Write-Host sqlplus username/password`@$args `@$script.Name

关于powershell - 如何在 PowerShell 中使用 @ 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/812882/

相关文章:

powershell - 查询访问权限的 Powershell 上的监控工具

powershell - 在Powershell中输出磁盘使用情况

c# - Powershell Add-Type 在编译 .dll (C#) 时禁止创建 .pdb

PowerShell 函数不会返回 DataTable

windows - Powershell If 语句不接受多个 OR 条件

Powershell cat 命令 - 为什么输出文件大小远大于输入文件大小的总和?

node.js - 如何从 gulp 调用执行 PowerShell 脚本?

PowerShell:限制变量值

azure - 用户上次登录 - 导出

powershell - 在 PowerShell 中将参数传递给 $webclient.DownloadFile()