LINUX SHELL SCRIPTING

BY SOURABH MISHRA

Sourabh Mishra
2 min readApr 26, 2021

DAY 1 —

  • > Shell is a UNIX term for an interface between a user and an operating system service. Shell provides users with an interface and accepts human-readable commands into the system and executes those commands which can run automatically and give the program’s output in a shell script.
  • > Script is a program that contains a series of commands to be executed. These commands are executed by an interpreter. Anything you can put into a command line, you can put in a script. And, scripts are great for automating tasks.
  • > Shell Scripting is an open-source computer program designed to be run by the Unix/Linux shell. Shell Scripting is a program to write a series of commands for the shell to execute.
  • > Types of Shell:

* The C Shell — Denoted as csh

* The Bourne Shell — Denoted as sh

* The Korn Shell — Denoted as ksh

* GNU Bourne-Again Shell — Denoted as bash

  • > The while loop enables you to execute a set of commands repeatedly until some condition occurs. It is usually used when you need to manipulate the value of a variable repeatedly.

DAY 2 —

  • > Awk is a scripting language used for manipulating data and generating reports
  • > The awk command programming language requires no compiling, and allows the user to use variables, numeric functions, string functions, and logical operators.
  • > The Awk command is used as follows: $ awk options ‘selection _criteria {action }’ input-file > output-file The options can be: -f program files: It reads the source code of the script written on the awk command -F fs: It is used as the input field separator.
  • > NR: NR command keeps a current count of the number of input records. Remember that records are usually lines. Awk command performs the pattern/action statements once for each record in a file.
  • > NF: NF command keeps a count of the number of fields within the current input record.
  • > FS: FS command contains the field separator character which is used to divide fields on the input line. The default is “white space”, meaning space and tab characters. FS can be reassigned to another character (typically in BEGIN) to change the field separator.
  • >sed performs basic text transformations on an input stream (a file or input from a pipeline) in a single pass through the stream, so it is very efficient.
  • > Any codes we write particularly to execute any task from one line to multi-line are command. The function is a block of code we used to write for reusability, addressing particular sets of problems, computations. It can consist of one to multiple numbers commands.

--

--