Shell Scripting in Linux

12
Shell Scripting Linux shell programming 10/25/22

description

Tells about the shells and how to get started with shell programming.with a snapshot of a basic shell script.

Transcript of Shell Scripting in Linux

Page 1: Shell Scripting in Linux

Shell ScriptingLinux shell programming

04/12/23

Page 2: Shell Scripting in Linux

Introduction • A shell is a program constructed of shell commands

( $shell,$path,Ls,pwd,mkdir..)• Shell is an environment for user interaction.But it is

not a part of kernel.• Shell is just like as BAT files in MS-DOS.• By default,Bash shell is default shell for Linux.

04/12/23

Page 3: Shell Scripting in Linux

Features of Shells• Shells are CASE SENSITIVE.• Shells allows interaction with kernel.• Shells allow one to create functions and pass

arguments to them.• Shells provide help for each and every command

using man or help.• Helps in automation of tasks and thus time saving

04/12/23

Page 4: Shell Scripting in Linux

Types of shells• Following types of shells are available in linux:

Some other types of shells available are KSH Korn shell,TCSH tenex/Tops C shell

Shell Name Developer Prompt

Description

Bash – Bourne again

Brian Fox &Chet Ramey

$ Bash is the replacement of sh shell.It provides many tools for editing and manipulating history.

CSH - C shell Bill Joy % C shell has its syntax much same as that of C language.

04/12/23

Page 5: Shell Scripting in Linux

Shell Scripting• A script is defined as just a plain text file or ASCII

file – with a set of linux / unix commands.– Flow of control– I\O facilities

• A shell script can be created using any

text editor like vim,emac,notepad++ etc.

04/12/23

Page 6: Shell Scripting in Linux

• Shell script allow use of variables.• Shell scripts are interpreted directly and are not

compiled as c\c++ codes.• Shells provide many features including loop

constructs,arrays,variables,branches and functions.• shells provide logic with other utilities like

pipelining,redirection etc.• Shells allow file and directory management features.

04/12/23

Page 7: Shell Scripting in Linux

Example of Shell scripting

04/12/23

Page 8: Shell Scripting in Linux

Structure of a script• #!/bin/bash –it defines that in which shell will be used

to run the script.• # comments –comments can be made by using #

symbol in a script.• Chmod +x script.sh – to tell the linux that file is

executable.• ./script.sh to execute the script.

To check current shell ,type following:

echo $SHELL.

04/12/23

Page 9: Shell Scripting in Linux

Advantages of shell scripting• Shell script is much quicker

than programming in any

other languages.

• To automate the frequently

performed tasks.

• Easy to use and understand.

Non-geeks can also modify

scripts.04/12/23

Page 10: Shell Scripting in Linux

Disadvantages of shell scripting

• Slow execution speed.

• Prone to costly errors.

• Compatability problems

04/12/23

Page 11: Shell Scripting in Linux

ReferencesShell Scripting for Unix/Linux: Shell scripting

advantages and disadvantages Bash Shell Script Function Examples Linux Shell Scripting Tutorial - A Beginner's

handbook LinuxHelp.net

04/12/23

Page 12: Shell Scripting in Linux

04/12/23