From the course: Learning Linux Shell Scripting

Printing to the console - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

Printing to the console

- [Instructor] The first tool that every shell script programmer needs is a text editor. This is not the same thing as a word processor. In fact, you should never use a word processor to edit a script. Vim is a free, and open source editor that has been around since the early 1990s. It is by and far the most popular editor for scripting. However, there is no requirement that you use it too. I am going to use Atom for this course. It is an open source editor from the folks at GitHub. It works well from a GUI, and is easily invoked from the command line. If you'd like to use it too it is available for free at atom.io. You are, of course, welcome to use any editor you'd like. Traditionally the first program created in a new language is Hello World. So let's honor that tradition, and make one ourselves. The first thing you need to know is the command which prints to the display, echo. I've already installed Atom in my machine, and I'm in the Terminal. Let's name our script hello.sh. So we'll type touch hello.sh. What did we just do? The touch command updates a file's timestamp if it exists, and if the file doesn't exist creates it. So we created an empty file named sh. There is no requirement that scripts have an extension, but I like to make the purpose of things painfully obvious. So I use the extension sh. The next command will launch Atom, and open it with our hello script ready to be edited. So we type atom hello.sh. The echo command prints to the display. Let's add our hello message. Echo hello comma world. You can save the file either with File, and then Save. Or, quickly, by using the keyboard shortcut Ctrl + S. Let's return to the Terminal. To execute our script we're gonna type bash hello.sh. Bash is a shell, and command language. It opens our script, and invokes the commands in it. We see the familiar greeting hello, world. Nice. We've created our first script, and got it to print to the screen.

Contents