ruby -e and global variables

8 views
Skip to first unread message

tcb...@gmail.com

unread,
Sep 24, 2021, 8:51:39 AMSep 24
to
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

August Werner

unread,
Sep 24, 2021, 3:09:12 PMSep 24
to
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.
Reply all
Reply to author
Forward
0 new messages