如果我定义一个groovy变量
def x = "anish$"
Run Code Online (Sandbox Code Playgroud)
它会给我带来错误,解决方法是
def x = "anish\$"
Run Code Online (Sandbox Code Playgroud)
除了形式"$"什么是需要反斜杠的黑名单字符,是否有一个列出保留字符的Groovy引用.大多数"语言规范"都提到了这些细节,但我没有在Groovy语言规范中看到它(许多"TODO"评论).
class A {
private def sayHello() {
println "Anish"
}
}
def a_obj = new A()
a_obj.sayHello()
Run Code Online (Sandbox Code Playgroud)
输出: Anish
有没有什么方法可以保护sayHello()groovy或我错过了什么?
在执行shell脚本时,如何知道它正在执行哪个行号,确实编写了一个包装器,我可以从shell脚本执行shell脚本并知道它正在执行哪个行号.
如何使用shell脚本从特定字符串中删除所有n个字符,
ssl01:49188,,,
ssl01:49188,
ssl01:49188,,,,,
ssl01:49188,ssl999999:49188,,,,,
ssl01:49188,abcf999:49188,,,,,
Run Code Online (Sandbox Code Playgroud)
输出将采用以下格式
ssl01:49188
ssl01:49188
ssl01:49188
ssl01:49188,ssl999999:49188
ssl01:49188,abcf999:49188
Run Code Online (Sandbox Code Playgroud) mongoDB集合包含以下数据
db.stack.find()
{ "_id" : "8GieRu" }
Run Code Online (Sandbox Code Playgroud)
_id不是12字节的单个字符串,
根据[ObjectID] [1]的MongoDB文档,id(字符串) - 可以是24字节的十六进制字符串,12字节的二进制字符串或数字.
使用Mongoose,可以使用此Json访问此集合
{"_id" : new mongoose.Types.ObjectId("8GieRu")}
Run Code Online (Sandbox Code Playgroud)
并抛出以下错误
/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js:35
throw new Error("Argument passed in must be a single String of 12 bytes or
^
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
at new ObjectID (/node_modules/mongoose/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js:35:11)
[1]: http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html
Run Code Online (Sandbox Code Playgroud)
Mongoose严格检查固定长度的ObjectId,如何使用给定长度的mongoose传递Object_id
执行ansible ping模块时出错
bash ~ ansible webservers -i inventory -m ping -k -u root -vvvv
SSH password:
<~> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO ~
<my-lnx> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO my-lnx
~ | FAILED => FAILED: [Errno 8] nodename nor servname provided, or not known
<my-lnx> REMOTE_MODULE ping
<my-lnx> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582 && echo $HOME/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582'
<my-lnx> PUT /var/folders/8n/fftvnbbs51q834y16vfvb1q00000gn/T/tmpP6zwZj TO /root/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582/ping
<my-lnx> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582/ping; rm -rf …Run Code Online (Sandbox Code Playgroud) 我正在使用Groovy 1.7.2.有些方法需要同步,有没有更多的方法可以做到这一点,或者我必须遵循相同的Java方式synchronized在方法之前放置关键字.
e.g : synchronized static def Map getMap(def fileName) { }
Run Code Online (Sandbox Code Playgroud) 在tomcat 7.0.29上运行web应用程序,同时停止应用程序时抛出以下错误
SEVERE: The web application [/helloWorld] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value
[com.sun.xml.bind.v2.ClassFactory$1@1b7b32c]) and a value of type [java.util.WeakHashMap] (value [{class
com.test.jaxws_asm.CreateSession=java.lang.ref.WeakReference@a06d25}]) but failed to remove it when the web application was stopped.
Threads are going to be renewed over time to try and avoid a probable memory leak.
Run Code Online (Sandbox Code Playgroud) 如何在我runcmd的cloud init脚本部分中使用管道重定向命令的输出?以下失败:
runcmd:
- [curl, -sk, https://example.com/packages/current/install.bash, '|', /bin/bash, -s, agent:certname=XYZ.com]
Run Code Online (Sandbox Code Playgroud)
它最终会创建一个如下所示的脚本:
'curl' '-sk' 'https://example.com/packages/current/install.bash' '|' '/bin/bash' '-s' 'agent:certname=XYZ.com'
Run Code Online (Sandbox Code Playgroud)
由于管道被引用,脚本失败.我怎样才能解决这个问题?
如何使用shell脚本合并两个属性文件,例如: - 如果我有两个属性文件,如:
first.properties
/test/file="anish"
/test/version=3.0
second.properties
/test/author=nath
/test/version=2.0
Run Code Online (Sandbox Code Playgroud)
如果我将first.properties合并到second.properties上,那么常见的现有属性应该取自first.properties,所以我的输出应该看起来像
final.properties
/test/file="anish"
/test/version=3.0
/test/author=nath
Run Code Online (Sandbox Code Playgroud)