Zsh variables, Ruby - somehow ARGV contains wrong number of elements
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.
Written by Bartłomiej Danek
Related protips
2 Responses
Looks like this is actually the expected behavior of zsh and has nothing to do with ruby (that is you would see the same thing for a program in any language run under zsh). For a bit more explination and some possible solutions see: http://unix.stackexchange.com/questions/19530/expanding-variables-in-zsh
@khalsah thanks for the link!