Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing bash a value with leading hyphen

Tags:

bash

ruby

trollop

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 => ""
end
like image 242
Ben Walker Avatar asked Sep 06 '25 19:09

Ben Walker


1 Answers

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

-v xxxx
--value=xxxx

Now it's sometimes possible to do:

-vxxxx

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

--value=-value
like image 174
tadman Avatar answered Sep 08 '25 10:09

tadman