I have a doubt concerning #{$$} inside a double quoted string, in concrete I have this string:
"#{command}#{$$}#{(Time.now.to_f * 1000).to_i}"
If I execute "#{$$}" in console I get an integer number but I would like to read an explanation to this.
Thank you !!
$$ is the interpreter's process ID.
Ruby has quite a few global variables you can use, see here.
That would be the global process ID.
If you're asking what the #{...} syntax means, that prints the variable inside the braces. So if it would work like this..
command = "print"
puts "cmd: #{command}" #=> cmd: print
Related
Is this possible? So lets say that we have this script: loadstring("print('Hello')")() this script is really easy to get the source from by just doing:
loadstring = print
loadstring("print('Hello')")()
Is it possible to disable this? Btw this is for my obfuscator
I am really sorry if this thread was confusing, Thanks
Maybe helpful: execute lua string as lua code.
So, the code must be:
trueloadstring = loadstring
loadstring = print
loadstring ("print('Hello')") -- prints "print('Hello')"
trueloadstring ("print('Hello')")() -- prints "Hello"
I am trying to loadstring a string and run it as a function. Here is my problem:
a = "hello"
loadstring("print(a)")()
I dont want the code above to use any vars/funcs outside of it. My goal is to make the script above print nil since a isnt defined inside the loadstring.
Sorry if the question is very brief. It was hard to explain my problem.
Your variable a lives in the global environment. To keep your chunk from seeing it, you need to give it a different environment. In Lua 5.1, you'd do that like this:
a = "hello"
local chunk = loadstring("print(a)")
setfenv(chunk, {print = print})
chunk()
In Lua 5.2 or newer, you'd do that like this:
a = "hello"
load("print(a)", nil, "t", {print = print})()
It's important to note that print isn't magic. It won't be in the new environment unless you put it there explicitly, like I did.
I'm writing a jenkinsfile in VS Code and when I use docker.withRegistry("some.registry"){...} I get a brackets do not match error inside of code. It parses fine inside jenkins, but this error inside of code is bugging me a lot. As soon as anything goes between the {} I get the error show up on the closing bracket.
Even copying in directly from the documentation from the Jenkins website gives the same issue.
Any ideas?
Oddly enough I had the same issue when I was using a private registry with a credentials ID, when I switched away from single quotes to double quotes the error went away, you could give that a try?
docker.withRegistry("https://some.registry", "docker-registry-creds") {
def customImage = docker.build("my-image:${env.GIT_COMMIT}")
}
As mentioned by Carl here, this happens when you have the following 2 characters, in this particular order, in a single quoted string:
'/*'
So strings like the following will trigger the error:
'**/*.xml'
'/some/path/to/random/files/*.py'
Just use double quote in those strings, and all the errors will go away:
"**/*.xml"
"/some/path/to/random/files/*.py"
I noticed this also occurs when using a parenthesis in single quotes. Again fixed by putting these in double quotes.
e.g.:
def something= somethingelse.tokenize('(')
can be replaced by
def something= somethingelse.tokenize("(")
in Jenkins file one of the variable is having the comma separated values like below.
infra_services=[abc,def,xyz]
when I write the below code it was throwing an error.
if ("{$Infra_Services}".contains("xyz"))
then
echo "$Infra_Services"
fi
yes you can do if statements in a Jenkinsfile. However if you are using declarative pipeline you need to brace it with the step script.
Your issue comes from the fact you did not put any double quotes around "abc" and all the elements of your array
infra_services=[abc,def,xyz]
β
A second error will raise after you fix this. If infra_services is an array, to manipulate it you should not try to cast it as string. It should throw when you do "{$Infra_Services}"
here is a working example
βdef Infra_Services = ["abc","def","xyz"]
if (Infra_Services.contains("xyz")) {
println "found"
}ββ
My advice is to test your groovy before running it on jenkins, you will gain precious time. Here is a good online groovy console I use to test my code. running the groovy console from terminal is an alternative
https://groovyconsole.appspot.com/
I want to use sqlplus within ruby. Dont want to use any gems[bec I cannot get it installed on our servers without much help from other teams ..etc] and want to keep it very minimal.
I am trying something as simple as this in my ruby script:
`rlwrap sqlplus user/pswd#host << EOF`
`set serveroutput on;`
`commit;` #ERROR1: sh: commit: not found
sql = "insert /*+ APPEND*/ INTO table(col1, col2) values (#{data[0]},#{data[1]});"
`#{sql}` #ERROR2: sh: Syntax error: "(" unexpected
Can anyone help me with ERROR1 and ERROR2 above
Basically for "commit: not found" I think its getting executed on shell rather than in sqlplus. However seems like "set serveroutput on" seems to execute fine !
For ERROR2, I am clueless. I also tried using escape slash for the "/" in the sql.
Thanks
The answer is, don't use SQL*Plus. Don't call a command-line utility from inside your script; between the ruby-oci8 gem and the ruby-plsql gem, you can do anything you could accomplish from within SQL*Plus.
The reason you get the errors is that you are sending each line to the shell individually. If your entire statement was wrapped in a single pair of backticks, it might work.
But if you really are unable to install the proper gems, put the commands in a temporary file and tell sqlplus to execute that, eg:
require 'tempfile'
file = Tempfile.open(['test', '.sql'])
file.puts "set serveroutput on;"
file.puts "commit;"
file.puts "insert /*+ APPEND*/ INTO table(col1, col2) values (#{data[0]},#{data[1]});"
file.puts "exit;" # needed or sqlplus will never return control to your script
file.close
output = `sqlplus user/pswd#host ##{file.path}`
file.unlink
You'll have to be very careful about:
Quoting values (if using oci8/dbi you could use bind variables)
Error handling. If using ruby libraries, errors would raise exceptions. Using sqlplus, you'll have to parse the output instead. Yuck!
So it can be done but I highly recommend you jump through whatever hoops are required to get oci8 (and maybe ruby-DBI) installed properly :)
ps are you sure you want to commit before the insert?