Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过移动Ruby向Ruby脚本传递参数_Ruby_Bash_Shell - Fatal编程技术网

通过移动Ruby向Ruby脚本传递参数

通过移动Ruby向Ruby脚本传递参数,ruby,bash,shell,Ruby,Bash,Shell,我试图将命令行参数传递到一个Ruby脚本中,该脚本被调用时遇到了问题。我只是将他们的标准wrapper.sh文件用于带有gems的脚本: #!/bin/bash set -e # Figure out where this script is located. SELFDIR="`dirname \"$0\"`" SELFDIR="`cd \"$SELFDIR\" && pwd`" # Tell Bundler where the Gemfile and gems are.

我试图将命令行参数传递到一个Ruby脚本中,该脚本被调用时遇到了问题。我只是将他们的标准wrapper.sh文件用于带有gems的脚本:

#!/bin/bash
set -e

# Figure out where this script is located.
SELFDIR="`dirname \"$0\"`"
SELFDIR="`cd \"$SELFDIR\" && pwd`"

# Tell Bundler where the Gemfile and gems are.
export BUNDLE_GEMFILE="$SELFDIR/lib/vendor/Gemfile"
unset BUNDLE_IGNORE_CONFIG

# Run the actual app using the bundled Ruby interpreter, with Bundler activated.
exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/test.rb"
当我运行它时,我的Ruby脚本没有看到任何命令行参数。我已尝试将最后一行更改为:

exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/test.rb $@"
exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/test.rb" $@
我认为这会起作用,但当我用arg“arg1”测试它时,它给出了错误:

/[pathtofile]/test-1.0.0-osx/lib/ruby/bin.real/ruby: No such file or directory -- /[pathtofile]/test-1.0.0-osx/lib/app/test.rb arg1 (LoadError)
因此,它似乎将命令行参数视为文件名的一部分

有没有办法修改此脚本以正确传入参数


谢谢

显然,我是个白痴。当然,它将参数视为文件名的一部分,因为$@在引号中。最后一行的正确修改是: