Local Security Shell Scripting
Local Security Shell Scripting
Local Security Shell Scripting
Overview
A shell script is a program executed by the Unix shell. There are many shells to choose from,
the most common of which are the Bourne shell (sh), Bourne Again shell (bash), C shell (csh),
Korn shell (ksh), and Z shell (zsh).
Shell scripts are flexible and can be used to automate long, mundane, or complex tasks. A
great benefit to a shell script is that it uses the same commands and syntax as the those for
the command line, as well some common programming features.
In its simplest form, a shell script is a list of commands run in sequence. Every new line of
a shell script is a new command; indentation is used for large, multi-line commands.The
following basic script will report the logged in user and the present working directory of that
user when the script is run:
#!/bin/bash
whoami
pwd
Key Ideas
Shebang (or hashbang): The #! character set that precedes the file path (eg #!/bin/sh) of
the selected shell. This is the first line of the script and tells the kernel which interpreter to
use for the script.
#: The # is used for comments within the script. Anything on the line after this character will
not be interpreted as part of the script.
script_name.sh: The .sh suffix for a shell script file.
sh script_name.sh: The command for running the script on the command line.
clear: A command that clears the screen.
echo : A command that prints whatever string appears between the quotation marks on a
new line.
Example Scenario
Create a short shell script that clears the screen and prints Hello world! at the top.
Now Do It
1. Create a file called Hello_world.sh and open it in your chosen text editor.
22
23
Answer Key
The hello_world.sh script should look like this:
#!/bin/bash
# This script clears the screen and prints Hello world!.
clear
echo Hello world!
24
Get Certified!
Get more information at http://training.linuxfoundation.org/certification/lfcs