0% found this document useful (0 votes)
103 views

Shell Script

This document provides an overview of shell scripting in UNIX/Linux systems. It discusses what UNIX and commands are, defines shell scripts as programs run by the shell interpreter, and outlines popular shell flavors like Bourne, C, and Bash shells. It also gives examples of typical shell operations like file manipulation and program execution. Common shell scripting concepts are introduced like conditional statements, variables, and getting input. Sample shell scripts are provided like Hello World and a name input script.

Uploaded by

samira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Shell Script

This document provides an overview of shell scripting in UNIX/Linux systems. It discusses what UNIX and commands are, defines shell scripts as programs run by the shell interpreter, and outlines popular shell flavors like Bourne, C, and Bash shells. It also gives examples of typical shell operations like file manipulation and program execution. Common shell scripting concepts are introduced like conditional statements, variables, and getting input. Sample shell scripts are provided like Hello World and a name input script.

Uploaded by

samira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Shell Scripting

Titles
• UNIX
• What is a command?
• Shell script
• Flavors of Unix Shells
• Shell Operations
• Examples
UNIX
 Unix was developed by programmers and for
programmers.
 Unix is designed so that users can extend the
functionality
 To build new tools easily and efficiently
 To customize the shell and user interface.
 To string together a series of Unix commands to create new
functionality.
 To create custom commands that do exactly what we want.
What is a command?
In UNIX, a command is a program that you can run.
In Mac OS or Windows, you point to the program
and click it.
To turn on command in UNIX, you type the name
and Enter.
Example:
$ date [Enter]
Shell
• A program that interprets commands
• Allows a user to execute commands by typing them
manually at a terminal, or automatically in programs
called shell scripts.
• A shell is not an operating system. It is a way to
interface with the operating system and run
commands.
Shell script
A shell script is a computer program
designed to be run by the Unix
shell, a command-line interpreter.
It acts as an interface between the
user and OS (kernel).
It’s known as “ command
interpreter”.
Flavors of Unix Shells
 Two main flavors of Unix Shells
 Bourne (or Standard Shell): sh, ksh, bash, zsh
• Fast
• $ for command prompt
 C shell : csh, tcsh
• better for user customization and scripting
• %, > for command prompt
 To check shell:
 % echo $SHELL (shell is a pre-defined variable)
 To switch shell:
 % exec shellname (e.g., % exec bash)
Popular Shells
 sh Bourne Shell
 ksh Korn Shell
 csh,tcsh C Shell (for this course)
 bash Bourne-Again Shell
What is BASH?
• BASH = Bourne Again SHell

• Bash is a shell written as a free replacement to the standard


Bourne Shell (/bin/sh) originally written by Steve Bourne for
UNIX systems.

• It has all of the features of the original Bourne Shell, plus


additions that make it easier to program with and use from
the command line.

• Since it is Free Software, it has been adopted as the default


shell on most Linux systems.
Shell Operations
Typical operations performed by shell scripts include file
manipulation, program execution, and printing text. A script
which sets up the environment, runs the program, and does
any necessary cleanup, logging, etc. is called a wrapper.
Shell Programming
It’s a collections of executables or
commands placed in a file and executed.
It provides user an option to execute a
command based on some condition.
It provides conditional and control
statements.(if,for,while,switch-case
etc)
 Programming Shell can do
Customization of a Unix session
Scripting
Shell script Examples
1 - Hello World program
#!/bin/sh
echo "Hello world“
2 – hello world program by variable initialization
#!/bin/sh
MyMessage=“Hello world”
Echo $MyMessage
Note: don’t use space before and after = operator.
3 – Getting info from user
#!/bin/sh
Echo what is your name?
Read MyName
Echo “hello $MyName”

You might also like