Zsh variables, Ruby – somehow ARGV contains wrong number of elements

Posted on

I found strange thing in Ruby and Zsh – these two tools do not work well together. I use:

  • ruby 1.9.3p392
  • zsh 4.3.11

And simple script

$ cat argv.rb
p ARGV # print on screen passed arguments

Example with arguments passed through command line:

$ ruby argv.rb --tag key:value
["--tag", "key:value"]
# --> it's okay, array should include 2 elements

Example with arguments passed through variable:

$ export PARAMS="--tag key:value"
$ ruby argv.rb $PARAMS
["--tag key:value"]
# --> one element - something went wrong

Switch shell to bash and run it again:

$ bash
bash-3.2$ ruby argv.rb --tag key:value
["--tag", "key:value"] 
# --> two elements
bash-3.2$ export PARAMS="--tag key:value"
bash-3.2$ ruby argv.rb $PARAMS
["--tag", "key:value"]
# --> two elements 

For bash everything is okay, somehow zsh passes/generates variables different way. If anybody knows how to make it work with zsh, please leave a comment.

Anyway be careful when you are using zsh variables, ruby and ARGV constant.

Leave a Reply

Your email address will not be published.