问题描述:

I'm trying to pass command line arguments into a Ruby script that's being called with Traveling Ruby and having trouble making it work. I'm just using their standard wrapper.sh file for scripts with 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"

When I run it, my Ruby script doesn't see any command line arguments. I've tried changing the last line to:

exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/test.rb [email protected]"

which I thought would work, but when I test it with an arg "arg1" it's giving me the error:

/[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)

So it seems like it's treating the command line argument as part of the filename.

Is there a way to modify this script to properly pass in arguments?

Thanks!

网友答案:

Obviously, I'm an idiot. Of course it was treating the argument as part of the filename because the [email protected] was inside the quotes. The correct modification to the last line to make everything work is:

exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/test.rb" [email protected]
相关阅读:
Top