How can I create a bash script which runs irb, then some ruby code? The Next CEO of Stack OverflowHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to use specify version of ruby for shell script with rbenv?How can I syntax highlight Ruby range bounds in gtksourceview3.0?cpulimit on a bash script which runs other commandsBash script only runs in debug modeHow can I check the ruby format for a bunch of files and/or a single file?Ruby gems not recognized in bash scriptHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to iterate over files using awk, bash, or ruby?How can I use ruby gem commands like bundler when ruby is installed by nix package manager?Create Bash Script to Wait and then Run

What steps are necessary to read a Modern SSD in Medieval Europe?

Which one is the true statement?

Is fine stranded wire ok for main supply line?

Yu-Gi-Oh cards in Python 3

Physiological effects of huge anime eyes

What does "shotgun unity" refer to here in this sentence?

Is French Guiana a (hard) EU border?

Spaces in which all closed sets are regular closed

Ising model simulation

Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?

Towers in the ocean; How deep can they be built?

What day is it again?

Is it correct to say moon starry nights?

Expressing the idea of having a very busy time

Is there a way to save my career from absolute disaster?

Can you teleport closer to a creature you are Frightened of?

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?

How to Implement Deterministic Encryption Safely in .NET

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Vector calculus integration identity problem

Won the lottery - how do I keep the money?

Is it professional to write unrelated content in an almost-empty email?

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

Point distance program written without a framework



How can I create a bash script which runs irb, then some ruby code?



The Next CEO of Stack OverflowHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to use specify version of ruby for shell script with rbenv?How can I syntax highlight Ruby range bounds in gtksourceview3.0?cpulimit on a bash script which runs other commandsBash script only runs in debug modeHow can I check the ruby format for a bunch of files and/or a single file?Ruby gems not recognized in bash scriptHow can I launch irb from a bash script, execute some commands, then pass the irb session to the console?How to iterate over files using awk, bash, or ruby?How can I use ruby gem commands like bundler when ruby is installed by nix package manager?Create Bash Script to Wait and then Run










2















I'm trying to do this to make unit testing a breeze for myself.



The contents of an example script in question are as follows:



irb
require 'random_utils.rb'
a = SuccessChecker.new


Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.










share|improve this question




























    2















    I'm trying to do this to make unit testing a breeze for myself.



    The contents of an example script in question are as follows:



    irb
    require 'random_utils.rb'
    a = SuccessChecker.new


    Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.










    share|improve this question


























      2












      2








      2


      1






      I'm trying to do this to make unit testing a breeze for myself.



      The contents of an example script in question are as follows:



      irb
      require 'random_utils.rb'
      a = SuccessChecker.new


      Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.










      share|improve this question
















      I'm trying to do this to make unit testing a breeze for myself.



      The contents of an example script in question are as follows:



      irb
      require 'random_utils.rb'
      a = SuccessChecker.new


      Right now this just opens irb. I'd like to be able to run arbitrary code afterward, so that I might make scripts to make my life easier by requiring files, instantiating classes, populating test conditions, etc.







      bash ruby test






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 8 '12 at 22:56







      ac7v

















      asked Aug 8 '12 at 22:41









      ac7vac7v

      134




      134




















          3 Answers
          3






          active

          oldest

          votes


















          2














          You are executing commands sequentially, so the shell executes irb, waits until irb get closed and executes the next command (in your case require 'random_utils.rb')…



          What you want is to provide the script to irb via STDIN



          irb <<EOF
          require 'random_utils.rb'
          a = SuccessChecker.new
          EOF


          But this will probably not do what you want as irb is for interactive use, you should consider using your normal ruby interpreter instead, e.g:



          ruby <<EOF
          require 'random_utils.rb'
          a = SuccessChecker.new
          EOF





          share|improve this answer























          • I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

            – ac7v
            Aug 8 '12 at 23:21











          • @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

            – Ulrich Dangel
            Aug 8 '12 at 23:25











          • I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

            – ac7v
            Aug 8 '12 at 23:32


















          0














          Looks like you're ready to take the next step and use a unit testing library.



          Here's an introduction to minitest, built into Ruby 1.9.






          share|improve this answer























          • Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

            – ac7v
            Aug 13 '12 at 3:03











          • Cool, hope you enjoy it :)

            – Cawflands
            Aug 13 '12 at 7:03


















          0














          A modern solution to this is to use the pry gem and make this a plain old ruby script.



          #!/usr/bin/env ruby

          require 'pry'
          require 'random_utils.rb'
          a = SuccessChecker.new
          binding.pry


          will dump you into a debugger wherever binding.pry is...






          share|improve this answer








          New contributor




          Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f45099%2fhow-can-i-create-a-bash-script-which-runs-irb-then-some-ruby-code%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You are executing commands sequentially, so the shell executes irb, waits until irb get closed and executes the next command (in your case require 'random_utils.rb')…



            What you want is to provide the script to irb via STDIN



            irb <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF


            But this will probably not do what you want as irb is for interactive use, you should consider using your normal ruby interpreter instead, e.g:



            ruby <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF





            share|improve this answer























            • I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

              – ac7v
              Aug 8 '12 at 23:21











            • @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

              – Ulrich Dangel
              Aug 8 '12 at 23:25











            • I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

              – ac7v
              Aug 8 '12 at 23:32















            2














            You are executing commands sequentially, so the shell executes irb, waits until irb get closed and executes the next command (in your case require 'random_utils.rb')…



            What you want is to provide the script to irb via STDIN



            irb <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF


            But this will probably not do what you want as irb is for interactive use, you should consider using your normal ruby interpreter instead, e.g:



            ruby <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF





            share|improve this answer























            • I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

              – ac7v
              Aug 8 '12 at 23:21











            • @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

              – Ulrich Dangel
              Aug 8 '12 at 23:25











            • I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

              – ac7v
              Aug 8 '12 at 23:32













            2












            2








            2







            You are executing commands sequentially, so the shell executes irb, waits until irb get closed and executes the next command (in your case require 'random_utils.rb')…



            What you want is to provide the script to irb via STDIN



            irb <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF


            But this will probably not do what you want as irb is for interactive use, you should consider using your normal ruby interpreter instead, e.g:



            ruby <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF





            share|improve this answer













            You are executing commands sequentially, so the shell executes irb, waits until irb get closed and executes the next command (in your case require 'random_utils.rb')…



            What you want is to provide the script to irb via STDIN



            irb <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF


            But this will probably not do what you want as irb is for interactive use, you should consider using your normal ruby interpreter instead, e.g:



            ruby <<EOF
            require 'random_utils.rb'
            a = SuccessChecker.new
            EOF






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 8 '12 at 23:00









            Ulrich DangelUlrich Dangel

            20.7k25971




            20.7k25971












            • I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

              – ac7v
              Aug 8 '12 at 23:21











            • @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

              – Ulrich Dangel
              Aug 8 '12 at 23:25











            • I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

              – ac7v
              Aug 8 '12 at 23:32

















            • I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

              – ac7v
              Aug 8 '12 at 23:21











            • @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

              – Ulrich Dangel
              Aug 8 '12 at 23:25











            • I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

              – ac7v
              Aug 8 '12 at 23:32
















            I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

            – ac7v
            Aug 8 '12 at 23:21





            I have been using irb to load these files manually and poke at the code to test it interactively, so I think that's what I want to do, though I might change my mind :) Thank you for this. I thought it would be some simple character or something.

            – ac7v
            Aug 8 '12 at 23:21













            @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

            – Ulrich Dangel
            Aug 8 '12 at 23:25





            @ac7v see i.imgur.com/t6gNQ.png for details, e.g. irb will show return values and echos the commands, that is probably not what you want - there is no real benefit from using irb to run non interactive things.

            – Ulrich Dangel
            Aug 8 '12 at 23:25













            I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

            – ac7v
            Aug 8 '12 at 23:32





            I suppose I'll just write the testing code in a separate .rb file (for cleanliness). I guess that's the better way of doing it anyway. I consider this an answer. Thank you again.

            – ac7v
            Aug 8 '12 at 23:32













            0














            Looks like you're ready to take the next step and use a unit testing library.



            Here's an introduction to minitest, built into Ruby 1.9.






            share|improve this answer























            • Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

              – ac7v
              Aug 13 '12 at 3:03











            • Cool, hope you enjoy it :)

              – Cawflands
              Aug 13 '12 at 7:03















            0














            Looks like you're ready to take the next step and use a unit testing library.



            Here's an introduction to minitest, built into Ruby 1.9.






            share|improve this answer























            • Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

              – ac7v
              Aug 13 '12 at 3:03











            • Cool, hope you enjoy it :)

              – Cawflands
              Aug 13 '12 at 7:03













            0












            0








            0







            Looks like you're ready to take the next step and use a unit testing library.



            Here's an introduction to minitest, built into Ruby 1.9.






            share|improve this answer













            Looks like you're ready to take the next step and use a unit testing library.



            Here's an introduction to minitest, built into Ruby 1.9.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 10 '12 at 16:41









            CawflandsCawflands

            1012




            1012












            • Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

              – ac7v
              Aug 13 '12 at 3:03











            • Cool, hope you enjoy it :)

              – Cawflands
              Aug 13 '12 at 7:03

















            • Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

              – ac7v
              Aug 13 '12 at 3:03











            • Cool, hope you enjoy it :)

              – Cawflands
              Aug 13 '12 at 7:03
















            Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

            – ac7v
            Aug 13 '12 at 3:03





            Bookmarked. Don't have enough rep to +1 you yet so I'm saying thank you instead!

            – ac7v
            Aug 13 '12 at 3:03













            Cool, hope you enjoy it :)

            – Cawflands
            Aug 13 '12 at 7:03





            Cool, hope you enjoy it :)

            – Cawflands
            Aug 13 '12 at 7:03











            0














            A modern solution to this is to use the pry gem and make this a plain old ruby script.



            #!/usr/bin/env ruby

            require 'pry'
            require 'random_utils.rb'
            a = SuccessChecker.new
            binding.pry


            will dump you into a debugger wherever binding.pry is...






            share|improve this answer








            New contributor




            Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.
























              0














              A modern solution to this is to use the pry gem and make this a plain old ruby script.



              #!/usr/bin/env ruby

              require 'pry'
              require 'random_utils.rb'
              a = SuccessChecker.new
              binding.pry


              will dump you into a debugger wherever binding.pry is...






              share|improve this answer








              New contributor




              Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















                0












                0








                0







                A modern solution to this is to use the pry gem and make this a plain old ruby script.



                #!/usr/bin/env ruby

                require 'pry'
                require 'random_utils.rb'
                a = SuccessChecker.new
                binding.pry


                will dump you into a debugger wherever binding.pry is...






                share|improve this answer








                New contributor




                Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.










                A modern solution to this is to use the pry gem and make this a plain old ruby script.



                #!/usr/bin/env ruby

                require 'pry'
                require 'random_utils.rb'
                a = SuccessChecker.new
                binding.pry


                will dump you into a debugger wherever binding.pry is...







                share|improve this answer








                New contributor




                Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer






                New contributor




                Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 2 days ago









                StephenStephen

                101




                101




                New contributor




                Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                Stephen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f45099%2fhow-can-i-create-a-bash-script-which-runs-irb-then-some-ruby-code%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                    Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                    Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.