Completely newbie simple powershell question I am trying to do the following - for each *.sql file in the current directory run
完全新手简单的powershell问题我正在尝试执行以下操作 - 对于当前目录中的每个* .sql文件运行
sqlplus username/password@connect_identifier_specified_in_argument @file_name
Here is what I have so far:
这是我到目前为止:
$scripts = dir *.sql
foreach($script in $scripts) {
write-host sqlplus username/password"@"$args "@"$script.Name
}
(I know write-host outputs it to the screen, I'm just trying to debug for now)
(我知道写主机将它输出到屏幕上,我现在只是想调试)
However, there is something funky with how powershell treats the @ character and when I run this I always get something like
然而,对于powershell如何处理@字符有一些时髦的东西,当我运行它时,我总是得到类似的东西
PS C:\code\scripts> C:\utils\run_sql_scripts_on.ps1 identifier
sqlplus username/password@identifier @ ALERTS.sql
See that space after the "@"? What gives?
在“@”之后看到那个空格?是什么赋予了?
2 个解决方案
#1
Escape the @ with a backtick (`).
用反引号(`)逃脱@。
write-host sqlplus username/password`@$args `@$script.Name
#2
PowerShell Community Extensions has a handy little utility (echoargs) for debugging this sort of problem:
PowerShell社区扩展有一个方便的小实用程序(echoargs)用于调试此类问题:
5>echoargs username/password"@"$args "@"$script.Name
Arg 0 is <username/password@>
Arg 1 is <@>
Arg 2 is <test.txt>
Try escaping with a backtick:
尝试使用反引号转义:
6>echoargs "username/password`@$args" "`@$($script.Name)"
Arg 0 is <username/password@>
Arg 1 is <@test.txt>
#1
Escape the @ with a backtick (`).
用反引号(`)逃脱@。
write-host sqlplus username/password`@$args `@$script.Name
#2
PowerShell Community Extensions has a handy little utility (echoargs) for debugging this sort of problem:
PowerShell社区扩展有一个方便的小实用程序(echoargs)用于调试此类问题:
5>echoargs username/password"@"$args "@"$script.Name
Arg 0 is <username/password@>
Arg 1 is <@>
Arg 2 is <test.txt>
Try escaping with a backtick:
尝试使用反引号转义:
6>echoargs "username/password`@$args" "`@$($script.Name)"
Arg 0 is <username/password@>
Arg 1 is <@test.txt>