What Is Shell Scripting
What Is Shell Scripting
Shell scripting is writing a series of command for the shell to execute. It can combine lengthy
and repetitive sequences of commands into a single and simple script, which can be stored
and executed anytime. This reduces the effort required by the end user.
1. Create a file using a vi editor(or any other editor). Name script file with extension .sh
2. Start the script with #! /bin/sh
3. Write some code.
4. Save the script file as filename.sh
5. For executing the script type bash filename.sh
"#!" is an operator called shebang which directs the script to the interpreter location. So, if we
use"#! /bin/sh" the script gets directed to the bourne-shell.
#!/bin/sh
ls
#comment
For example, the following creates a shell variable and then prints it:
variable ="Hello"
echo $variable
#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"
Let's understand, the steps to create and execute the script
As you see, the program picked the value of the variable 'name' as Joy and 'remark' as
excellent.
This is a simple script. You can develop advanced scripts which contain conditional
statements, loops, and functions. Shell scripting will make your life easy and Linux
administration a breeze.
Bourne again shell (Bash) is a free Unix shell that can be used in place of the Bourne shell. It is a
complete implementation of the IEEE Portable Operating System Interface for Unix (POSIX) and
Open Group shell specification.
Bash is basically a command processor that typically runs in a text window, allowing the user to type
commands that cause actions. It can read commands from a file, called a script. Like all Unix shells it
supports the following:
A Unix shell is a command-line interpreter that provides users with a basic user interface. It allows
users to communicate with the system through a series of commands that are typed in the command-
line window. There are no buttons or pop-up windows in a shell, simply lots and lots of text.
Essentially, Bash allows users of Unix-like systems to control the innermost components of the
operating system using text-based commands.
Bash has a number of extensions and runs on Unix-like operating systems like Linux and Mac OS X.
It was ported to Windows through the Subsystem for UNIX-based Applications (SUA) and by POSIX
emulation using Cygwin or MSYS. It can even be used in MS-DOS.