shoppingvast.blogg.se

Ruby runner to execute script
Ruby runner to execute script








Puts is a method that’s available to all Objects it’s mixed in from the Kernel module in Ruby. Let’s take a look at the second line of our script: hello.rb and get the output of our program! The +x specifies that the script should be executable. chmod is a shell command that allows us to change the permissions for a file. You can make the script executable with the following command: chmod +x hello.rb.

RUBY RUNNER TO EXECUTE SCRIPT MAC

Mac users need to make the file executable by changing its permissions. Whoops! You’ll get the following error: bash. Windows users should get Hello World! returned just fine.

ruby runner to execute script

We can run our script without typing ruby in front of the file name (as long as we have the shebang). The majority of the Ruby files we'll create in this course will not be script files. Note that you only need a shebang for script files that you'll need to run in the terminal. We’ll see one of the reasons why in a moment. Even so, our scripts should always begin with a shebang. This is because the shell will check the default path and find the interpreter anyway.

ruby runner to execute script

Technically, our script would work even if we didn’t include a shebang (at least on the computers at Epicodus). For instance, if our script was written in Python, our shebang would look like this: #!/usr/bin/env python. If we were writing a script in another language, we’d provide the path to that interpreter instead. This line provides the shell (in our case, bash) with the absolute path to the Ruby interpreter. The opening line is called a shebang because of the first two characters #!. Let’s take a look at the content of the script itself. The output of the program will be Hello world!. We can run this script in the command line by going to the directory where the file lives and typing in ruby hello.rb.








Ruby runner to execute script