Professional Documents
Culture Documents
Week-2
Shell
Introduction to Linux Shell and Shell
Scripting
• If you are using any major operating system you are indirectly interacting
to shell.
• If you are running Ubuntu, Linux Mint or any other Linux distribution, you
are interacting to shell every time you use terminal.
• so before understanding shell scripting we have to get familiar with following
terminologies
• Kernel
• Shell
What is kernel?
• A shell in a Linux operating system takes input from you in the form of
commands, processes it, and then gives an output. It is the interface
through which a user works on the programs, commands, and scripts.
A shell is accessed by a terminal which runs it.
• BASH (Bourne Again SHell) – It is most widely used shell in Linux systems. It is
used as default login shell in Linux systems and in macOS. It can also be
installed on Windows OS.
• CSH (C SHell) – The C shell’s syntax and usage are very similar to the C
programming language.
• KSH (Korn SHell) – The Korn Shell also the base for the POSIX Shell standard
specifications etc.
• Each shell does the same job but understand different commands and
provide different built in functions.
Shell script
A shell script have syntax just like any other programming language. If
you have any prior experience with any programming language like
Python, C/C++ etc. it would be very easy to get started with it.
• Sh file1.sh
Ex2: Print details of a person
• ((sum = 25 +35 ))
• ((area=5*5))
• Echo $area
Ex 5: The While loop
• i=0
• while [ $i -le 2 ] //i less than equal to 2
• do
• echo Number: $i
• ((i++))
• done
Ex 6: The for loop
read num
if [[ $num -gt 10 ]]
then
echo "Number is greater than 10."
fi
Some of the commands:
INPUT:
• if [ $# -ne 0 ]
• then
• echo “enter the word”
• read word
• for fname in $*
• do
• if [ -f $fname ]
• then
• echo “ the given input file name is $fname”
• grep –v “$word” $fname
• else
• echo “ $fname is a not a file”
• fi
• done
• else
• echo “enter at least one argument as input”
• fi
• INPUT:
• ## I am creating two files names are del , dell.
• Gcet@ubuntu:~$ gedit del
• unix is os
• dos is also os
• here using unix
• unix is powerful os
• ---------------------------
• Gcet@ubuntu:~$ gedit dell
• windowsnt is also os
• there are some difference between unix and windows
• but unix is great among all os
• OUTPUT:
• Gcet@ubuntu:~$ sh Prog2.sh del dell
• enter the word
• os
• the given input file name is del
• here using unix
•
• the given input file name is dell
• there are some difference between unix and windows