Create a test.rb file in the home directory with the following parameters:
hello #!/usr/bin/ruby p "here"
Now, if we try to run it:
ruby -C /home/my_home test.rb
Which means changing the working directory in / home / my _home and running test.rb, you get an error message:
test.rb:1:in `<main>': undefined local variable or method `hello' for main:Object (NameError)
If we run it with:
ruby -x /home/my_home test.rb
We will print "here" and we will not get an error. The difference between main between -x and -C is that -x removes everything up to the line #!/usr/bin/ruby . And you also don't need to install the directory on cd when using -x. Since the main purpose of -x is to delete lines, and if necessary, it also includes -C functionality.
cd /home/my_home; ruby -x test.rb
See (ruby --help)
- -Cdirectory cd to the directory before executing the script
- -x [directory] disable text to line #! ruby and possibly cd to directory
As for -I. You can provide directories in which ruby ββwill look for the file that you are executing or requiring.
ruby -x test.rb
Ruby will not find the test.rb file unless you are in / home / my _home. But if you add -I, Ruby will look for test.rb in "/ home / my_home" too.
ruby -x -I/home/my_home test.rb
The difference with -C is that it will not change the directory before execution, but will just look for files there.
source share