Shell Scripting concepts

Bhavesh S. Sonewale
3 min readApr 27, 2021

πŸ‘‰ What is shell scripting?

Combining multiple commands in single file and then running that file using shell to automate our use-case is shell scripting.

πŸ‘‰ Introduction of operating system interfaces

Types of operating system interface :-
i) CLI, ii) GUI.

πŸ‘‰ What is the command-line interface?

It is an interface where we instruct the OS by giving the commands on a black screen i.e. shell.

πŸ‘‰ What is the shell?

Shell is a program that is primarily present in every OS and is written in some language like BASH/C/SH.

πŸ‘‰ What is bash shell?

Bash is a shell program that helps to execute the script or programs, bash is an updated version of the sh shell.

πŸ‘‰ What is a variable? and its type?

Variables are use to store the data. Types of variable :-
i) pre-defined variable
ii) user defined variable
iii) environment variable.

πŸ‘‰ What is an exit code?

When we run any command they throw number which specifies that whether the command ran or executed successfully or not. This number is called as exit code.

πŸ‘‰ What is the script?

List of command in proper sequence written in the file is script.

πŸ‘‰ Difference between command and script

Script is group of command in file use to automate our task whereas command is use to execute particular task manually.

πŸ‘‰ What is the use of hashbang /shebang

Hashbang/shebang is use to define which shell you are using whether it is sh, bash, etc.

πŸ‘‰ How to parameterize the script?

We can parameterize by using parameterized arguments $1,$2,etc .

πŸ‘‰ Describe β€˜awk’ command.

Awk is mostly used for pattern scanning and processing. It searches one or more files to see if they contain lines that matches with the specified patterns.

πŸ‘‰ Describe β€˜watch’ command?

Watch command is use to monitor program/ output of another command continuously.

πŸ‘‰ Write the command for getting the total number of false client hits.

β€œawk β€˜$9==404 {print $0}’ access_log | sort | uniq | wc -l” is the command for getting the total number of false client hits.

πŸ‘‰ tail command is used for?

β€˜tail’ command is used to get the output of last 10 commands of a file. -n <number> option can be given to change no of lines.

πŸ‘‰How to get filter dd:mm:yy from date output?

To get filter dd:mm:yy from the date output, we use the command:- date +%e:%b:%G.

πŸ‘‰ How to run multiple commands altogether?

To run multiple commands in a single line, we can separate the commands by β€œ;” or β€œ&&” or β€œ||” depending upon the use case.

πŸ‘‰ Write the command to create multiple files without redundancy.

To create n files without redundancy we use the command:- touch a{1….n}.txt

πŸ‘‰What are the different options available for awk command and their purpose?

The different options available for the awk command are:-
->-F :- Used for specifying the delimiter.
->END:- Used for getting the last line of the output produced by the awk.
->NF:- Used to display the total number of fields in unsorted data.
->NR:- Used to display the row number of each row.

πŸ‘‰How to create function in shell script?

To create function in shell scripting, we follow the syntax:- β€œ function_name() { body; } ”.

--

--

Bhavesh S. Sonewale

2x Red Hat Certified | Aspiring DevOps Engineer | Aviatrix Certified Engineer| AWS | Ansible | Openshift | Docker | Kubernetes