Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: August Werner Newsgroups: comp.lang.ruby Subject: Re: ruby -e and global variables Date: 24 Sep 2021 19:09:07 GMT Lines: 33 Message-ID: References: <43e02e5e-06a7-4a00-bcf8-69154b9c64fdn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 8f0bdtm7L+/Z/25HSKVq8QWSlCUtv8UowaTjEeT5TLJad81g== Cancel-Lock: sha1:DheDr3rAJRkRInBfydIHyOnz/nI= User-Agent: Pan/0.146 (Hic habitat felicitas; 8107378 git@gitlab.gnome.org:GNOME/pan.git) Xref: csiph.com comp.lang.ruby:7445 tcb...@gmail.com wrote: > I'm trying to assign a global variable when using ruby -e > `ruby -e "$a=3"` > -e:1: syntax error, unexpected '=' > > So it seems I can't assign global variables when using ruby -e > What I wanted is to assign $stdout = StringIO.new > so I capture the output Hello, Your problem with ruby -e "$a=3" and therefore also with ruby -e "$stdout = StringIO.new". Regardless of whether this makes sense, you have a problem with the shell (or perhaps other command line interpreter). You are using an unprotected ruby command text with characters that the shell interprets for itself. With: ruby -e '$a=3' or ruby -e "\$a=3" no one complains anymore.