Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
76 views

What Is Shell Scripting

Shell scripting allows users to automate repetitive tasks by writing scripts composed of shell commands. To create a shell script, a file is created with a .sh extension and given execute permissions. The script is executed by typing its name at the command line. Variables can be used to store and pass data in scripts. Comments are added with a #. The Bourne Again Shell (Bash) is a widely used command line shell that provides features for command execution, variables, conditionals and more. It allows users to control the operating system through text commands.

Uploaded by

Aziz Ur Rehman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

What Is Shell Scripting

Shell scripting allows users to automate repetitive tasks by writing scripts composed of shell commands. To create a shell script, a file is created with a .sh extension and given execute permissions. The script is executed by typing its name at the command line. Variables can be used to store and pass data in scripts. Comments are added with a #. The Bourne Again Shell (Bash) is a widely used command line shell that provides features for command execution, variables, conditionals and more. It allows users to control the operating system through text commands.

Uploaded by

Aziz Ur Rehman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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.

Let us understand the steps in creating a Shell Script

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.

Let's create a small script -

#!/bin/sh
ls

Let's see the steps to create it -


Command 'ls' is executed when we execute the scrip sample.sh file.

Adding shell comments


Commenting is important in any program. In Shell programming, the syntax to add a
comment is

#comment

Let understand this with an example.

What are Shell Variables?


As discussed earlier, Variables store data in the form of characters and numbers. Similarly,
Shell variables are used to store information and they can by the shell only.

For example, the following creates a shell variable and then prints it:

variable ="Hello"
echo $variable

Below is a small script which will use a 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.

What does Bourne Again Shell (Bash) mean?

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:

 File name wildcarding


 Piping
 Hear documents
 Command execution
 Variables and control structures for condition testing and iteration

Techopedia explains Bourne Again Shell (Bash)


Bash was written for the GNU Project by Brian Fox. It is called Bourne again shell for many reasons,
the first being that it is the open-source version of the Bourne shell and the second as a pun on the
concept of being born again. Its acronym is also a description of what the project did, which was to
bash together sh, csh, and ksh features.

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.

You might also like