Ben Walker Ben Walker - 2 years ago 72
Ruby Question

passing bash a value with leading hyphen

I have a bash command that requires a string value after "-v". When this string value has a leading "-", bash tries to interpret it as a new option of the bash command rather than the value I'm trying to give for -v. Is there a way I can escape this leading hyphen? I tried

-v -- -myValue
but then it tells me "option '-v' needs a parameter."

The command is calling a ruby file. I think this is the meaningful part of the ruby code for the purposes of this question:

opts = Trollop::options do
opt :method, "Encrypt or Decrypt", :short => "m", :type => :string, :default => "decrypt"
opt :value, "Value to Decrypt or Encrypt", :short => "v", :type => :string, :default => ""

Answer Source

There's two conventional ways to specify arguments, but these are not enforced at the shell level, they're just tradition:

-v xxxx

Now it's sometimes possible to do:


If you have a value with a dash and it's not being interpreted correctly, do this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download