Free Hosting Online for WorkStations

< Previous | Contents | Next >

Script File Format

In keeping with programming tradition, we’ll create a “hello world” program to demon- strate an extremely simple script. So let’s fire up our text editors and enter the following script:



#!/bin/bash

# This is our first script. echo 'Hello World!'

#!/bin/bash

# This is our first script. echo 'Hello World!'


The last line of our script is pretty familiar, just an echo command with a string argu- ment. The second line is also familiar. It looks like a comment that we have seen used in many of the configuration files we have examined and edited. One thing about comments in shell scripts is that they may also appear at the ends of lines, like so:



echo 'Hello World!' # This is a comment too

echo 'Hello World!' # This is a comment too


Everything from the # symbol onward on the line is ignored. Like many things, this works on the command line, too:


[me@linuxbox ~]$ echo 'Hello World!' # This is a comment too

Hello World!

[me@linuxbox ~]$ echo 'Hello World!' # This is a comment too

Hello World!


Though comments are of little use on the command line, they will work.

The first line of our script is a little mysterious. It looks as if it should be a comment, since it starts with #, but it looks too purposeful to be just that. The #! character se- quence is, in fact, a special construct called a shebang. The shebang is used to tell the system the name of the interpreter that should be used to execute the script that follows. Every shell script should include this as its first line.

Let’s save our script file as hello_world.


Top OS Cloud Computing at OnWorks: