简体   繁体   中英

Escaping @ in Windows environment variable

I have the following lines in a bat file:

SET LIB="C:\tools\oracle\main\ojdbc8.jar"
SET DRIVER="Java::oracle.jdbc.driver.OracleDriver"
SET CONN="jdbc:oracle:thin:@//localhost:1521/XE"

logstash -f logstash.conf

The two first SETs work fine, but the logstash program complains that the CONN variable is not a valid URI. I tried to put a ^ before the @ to escape it, but the problem persists. How can this be fixed?

You are currently including doublequotes as part of the variable value strings. I would recommend instead using the following syntax when set ting your variables:

Set "VarName=StringValue"

You would then doublequote %VarName% if/as required in any subsequent commands which use it .

In your provided example, I'd suggest that you therefore use:

Set "LIB=C:\tools\oracle\main\ojdbc8.jar"
Set "DRIVER=Java::oracle.jdbc.driver.OracleDriver"
Set "CONN=jdbc:oracle:thin:@//localhost:1521/XE"

And make independent decisions within your script on whether to use:

  1. %LIB% , %DRIVER% or %CONN%
  2. "%LIB%" , "%DRIVER%" or "%CONN%"
  3. !LIB! , !DRIVER! or !CONN! - (delayed expansion)
  4. "!LIB!" , "!DRIVER!" or "!CONN!" - (delayed expansion)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM