在调试 shell 脚本时,我发现使用xtraceon运行会很有帮助:
-x xtrace Print commands and parameter
assignments when they are exe-
cuted, preceded by the value
of PS4.
Run Code Online (Sandbox Code Playgroud)
例如:
$ set -x
$ s='Say again?'
+ s='Say again?'
# Other commands that might mess with the value of $s
$ echo $s
+ echo Say 'again?'
Say again?
Run Code Online (Sandbox Code Playgroud)
我知道,Ruby有交互式调试程序,如撬和byebug,但我正在寻找的东西,将很容易打开用于记录自动化脚本。
我确实找到了一个xtrace gem,但它与 PHP 格式有关。
我还看到有一个Tracer 类和一个TracePoint 类,它们似乎提供了一种在执行语句时打印语句的方法。但是我还没有找到任何打印变量值的方法(而不仅仅是变量名):
$ ruby -r tracer trace.rb
#0:/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:Kernel:<: return gem_original_require(path) …Run Code Online (Sandbox Code Playgroud) 如果我从两个数组开始,例如:
array1 = [{"ID":"1","name":"Dog"}]
array2 = [{"ID":"2","name":"Cat"}]
Run Code Online (Sandbox Code Playgroud)
如何将此数组合并为一个这样的数组?
arraymerge = [{"ID":"1","name":"Dog"}, {"ID":"2","name":"Cat"}]
Run Code Online (Sandbox Code Playgroud)