Book Image

Learning Linux Shell Scripting - Second Edition

By : Ganesh Sanjiv Naik
Book Image

Learning Linux Shell Scripting - Second Edition

By: Ganesh Sanjiv Naik

Overview of this book

Linux is the most powerful and universally adopted OS. Shell is a program that gives the user direct interaction with the operating system. Scripts are collections of commands that are stored in a file. The shell reads this file and acts on commands as if they were typed on the keyboard. Learning Linux Shell Scripting covers Bash, GNU Bourne Again Shell, preparing you to work in the exciting world of Linux shell scripting. CentOS is a popular rpm-based stable and secured Linux distribution. Therefore, we have used CentOS distribution instead of Ubuntu distribution. Linux Shell Scripting is independent of Linux distributions, but we have covered both types of distros. We start with an introduction to the Shell environment and basic commands used. Next, we explore process management in Linux OS, real-world essentials such as debugging and perform Shell arithmetic fluently. You'll then take a step ahead and learn new and advanced topics in Shell scripting, such as decision making, starting up a system, and customizing a Linux environment. You will also learn about grep, stream editor, and AWK, which are very powerful text filters and editors. Finally, you'll get to grips with taking backup, using other language scripts in Shell Scripts as well as automating database administration tasks for MySQL and Oracle. By the end of this book, you will be able to confidently use your own shell scripts in the real world.
Table of Contents (17 chapters)

When not to use scripts

Shell scripts have certain advantages over compiler-based programs, such as C or C++ language. However, shell scripting has certain limitations as well.

The following are the advantages:

  • Scripts are easy to write
  • Scripts are quick to start and easy for debugging
  • They save time in development
  • Tasks of administration are automated
  • No additional setup or tools are required for developing or testing
    shell scripts

The following are the limitations of shell scripts:

  • Every line in shell script creates a new process in the operating system. When we execute the compiled program, such as a C program, it runs as a single process for the complete program.
  • Since every command creates a new process, shell scripts are slow compared to compiled programs.
  • Shell scripts are not suitable if heavy math operations are involved.
  • There are problems with cross-platform portability.

We cannot use shell scripts in the following situations:

  • Where extensive file operations are required
  • Where we need data structures, such as linked lists or trees
  • Where we need to generate or manipulate graphics or GUIs
  • Where we need direct access to system hardware
  • Where we need a port or socket I/O
  • Where we need to use libraries or interface with legacy code
  • Where proprietary, closed source applications are used (shell scripts put the source code right out in the open for the entire world to see)