02. Important Symbols #, #!, ;, \

Let's go over some basic but important symbols encountered in a shell script.

Comments #

Commenting is performed with the # symbol. Anything written after a # symbol is ignored by the interpreter. Make sure to comment sufficiently throughout your scripting process!

#!shebang

The first line of a shell script may look like a comment since it starts with a pound symbol (#), but it's actually a shebang.

The shebang symbol indicates where to find the program that will be used to execute the script. Thus, the following line of code would indicate that the sh program (default shell executor) should be used to run the shell script, which is found in the /bin folder.

#!/bin/sh

Semicolons ;

A new line character symbolizes the completion of a command. If, however, you want to mark the end of a command and start a new one on the same line, use the semi-colon ;.

Backslash \

The backslash (\) can be used to break up a command line if it gets too long. Here is a contrived example:

$ echo hello world; echo \
> how \
> are \
> you
hello world
how are you

Our first shell script

Now let's make our very first shell script. First proceed by deciding on a name, and ensuring that it isn't already taken. We can do this with the which command.

$ which hello_world

No output? Great! That means that hello_world isn't already a command. Now let's create a normal file with the touch command.

$ touch hello_world

Now open this file and place the following two lines inside the script:

#/bin/sh
 
echo 'Hello world!'

All set! Now all we have to do is run (or execute) the file. This can be done in several different ways, which we'll see in the next lesson.

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

How Linux Works

Take your Linux skills to the next level! Try Linux & UNIX

In this completely revised second edition of the perennial best seller How Linux Works, author Brian Ward makes the concepts behind Linux internals accessible to anyone curious about the inner workings of the operating system. Inside, you'll find the kind of knowledge that normally comes from years of experience doing things the hard way.

$ Check price
39.9539.95Amazon 5 logo(114+ reviews)

More Linux & UNIX resources

Ad