Command Line Part 7

Steven Klavins
2 min readFeb 25, 2020

Week 1 — The command line

OK! now onto some advanced commands…

Quick tip, this works for Windows and Unix command lines, use “irb” to run ruby commands in the command line, this can be used for quick testing. Use the “exit” command to leave this and return to shell commands.

If we were to attempt running a ruby file straight from the command line, it is a possibility it wont run, this is due to our default permissions. Fear not we can use “chmod u+x” to grant ourselves permission, however this would not be the only thing we would need in order to run our ruby file.

If we were to do something such as “chmod u+x program.rb” our command line would try to run the ruby file as a normal shell command and would fail. However not to fear we can easily resolve this with a shebang command at the start of our program.

SHEBANG! (“#!”)

By adding a shebang command at the beginning of our program in our IDE we can instruct the command line how to run the file. First we need to find the path to our language’s interpreter, if we are looking for the Ruby interpreter we can enter the command “which ruby” (Windows you'll need to enter irb, then enter “RbConfig.ruby”).

So now we can add our shebang command in the programs code itself as “#!/path/location”. If we were to request the command line to run the file now it would execute successfully. Note though this will only run on your computer using this solution as the path on other peoples computers will be different.

Adding the “/usr/bin/env ruby” command would be the best solution to this problem as it loads the Ruby environment, meaning it will run on all computers.

Super user mode

A superuser has all rights and permissions to all programs and files on a computer, meaning you can delete anything, move anything, do anything as you wish. This however can be risky business and you need to proceed with extreme caution as one wrong move could have very bad consequences.

This should only be used if absolutely necessary, “sudo” is the command to enter super user mode. For example to remove a file that you can’t access with standard permissions you could use “sudo rm File”.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Steven Klavins
Steven Klavins

Written by Steven Klavins

Hi, I’m Steven, most call me Steve! I’m a programmer, musician, and artist. This blog contains various tutorials and posts related to software development.

No responses yet

Write a response