A shell script is a computer program designed to be run by the Unix/Linux shell. A shell is a command-line interpreter and typical operations performed by shell scripts include file manipulation, program execution, and printing text.

Types of Shell scripts are:

  • The Bourne Shell
  • The C Shell
  • The Korn Shell
  • The GNU Bourne-Again Shell

Why do we use shell scripts?

  • Shell scripts can be used to customize your environment
  • Will gain experience with shell variables, shell script operators, and logic structures

Previewing the Application:

  • Shell scripts can be used to customize your environment
  • Will gain experience with shell variables, shell script operators, and logic structures

Using Comments

Comments are important!

  • Provide useful documentation to both the programmer and to others who need to understand or debug the code
  • To use, start the comment line with a #

The Programming Shell

  • Bourne shell (sh)
  • Korn shell (ksh)
  • Bourne Again shell (bash)
  • POSIX shell (sh)

The different C-type shells follow −

  • C shell (csh)
  • TENEX/TOPS C shell (tcsh)

The original Unix shell was written in the mid-1970s by Stephen R. Bourne while he was at the AT&T Bell Labs in New Jersey.

 

Variables:

Variables are symbolic names that represent values stored in memory
Three types of variables:
– Configuration variables store information about the setup of the OS
– Environment variables hold information about your login session
– Shell variables are created at the command prompt or in shell scripts and are used to temporarily store
information

Shell Variables

  • Variables that you can define and manipulate for use with program commands in a shell
  • Observe basic guidelines for handling and naming shell variables

Shell Operators

Bash shell operators are in four groups:

  • Defining
  • Evaluating
  • Arithmetic
  • Redirection

Defining Operators

  • Used to assign a value to a variable
  • The most common is = (equal sign)
  • Use quotation marks with strings
  • Backquote says to execute the command inside the backquotes and store the result in the variable

Useful Links on Unix

  • Bell Labs − Gives an overview and history of the UNIX operating system. The Creation of the UNIX Operating System.
  • BSD UNIX − FreeBSD is an advanced UNIX operating system for modern server, desktop, and embedded computer platforms.
  • Linux Online − Linux is a free Unix-type operating system originally created by Linus Torvalds with the assistance of developers around the world.
  • Unix @ Wikipedia − A brief description of the Unix Operating system.