[英]How do I loop through elements of a bash array variable passed to a Ruby script via terminal?
I have a Bash file called test.sh
: 我有一个名为
test.sh
的Bash文件:
#!/bin/bash
arr=(whatever@gmail.com iamcool@gmail.com)
ruby testScript.rb $arr
And here's testScript.rb
: 这是
testScript.rb
:
ARGV.each{|a| p a}
When I run ./test.sh
in the terminal, I get this output: 在终端中运行
./test.sh
时,得到以下输出:
"whatever@gmail.com"
I want my Ruby script to loop through all elements in the Bash array variable $arr
. 我希望我的Ruby脚本循环遍历Bash数组变量
$arr
中的所有元素。 How do I fix my code to do this? 我该如何修正我的代码呢?
在bash脚本中,像这样传递数组:
ruby testScript.rb "${arr[@]}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.