• ruby -e and global variables

    From tcblues@gmail.com@21:1/5 to All on Fri Sep 24 05:51:34 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From August Werner@21:1/5 to tcb...@gmail.com on Fri Sep 24 19:09:07 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)