SlideShare a Scribd company logo
1 of 27
Shell Scripting (Bash shell only)
by - Akshay
Agenda
In this part of presentation, We will cover…
• Introduction to shell programming,
• How to read/write/execute a script.
Assumptions
Before starting with this you should know-
• How to use text editor such as vi/vim,
• Basic Linux commands.
December 15
What is SHELL ?
December 15
• Shell is just an interface to access an operating
system
• Shell reads command from user and tells Linux OS
what users want.
Shell
December 15
• Simply, the shell is a program that takes
your commands from the keyboard and
gives them to the operating system to
perform.
• In the old days, Shell was the only user
interface available on a Unix/Linux
computer. Nowadays, we have GUIs in
addition to the shell.
Some commands to play with shell
December 15
Tip: To find all available shells in your system type following command:
$ cat /etc/shells
Note that each shell does the same job, but each understand a different command
syntax and provides different built-in functions.
****In MS-DOS, Shell name is COMMAND.COM which is also used for same purpose,
but it's not as powerful as our Linux Shells are!
.
What is my current SHELL
December 15
Tip: To find your current shell type following command
$ echo $SHELL
Hint: Bash  which stands for Bourne Again SHell, an enhanced version of the original
Bourne shell program, sh, written by Steve Bourne
Tip: To find process-id of current shell.
$ ps -p $$
Further information
December 15
To read more information –
$man bash
$info bash
Mr. Shell
December 15
What is Shell Script & Why should I learn scripting
??
December 15
Shell Script
basically scripts are collections of commands that are
stored in a file. The shell can read this file and act on the
commands as if they were typed at the keyboard.
We have thousands of commands available for the
command line user, Can we remember them all? The
answer is, “No”. The real power of the computer is its
ability to do the work for you. To get it to do that, we
use the power of the shell to automate things. We write
scripts.
What are scripts good for?
December 15
A wide range of tasks can be automated. Here are some
of the things I automate with scripts:
• On every 1st day of a month, linux-servers backup their
configurations and copy it to a “Window/Storage machine“, and
delete old backups on successful execution so that we always have
latest backup with us. This is performed by a script.
• A script on a single click automatically does health check-up on
multiple servers and reports the status with colors (Red-> Critical,
Yellow-> Warning , Green -> OK) from all servers. A sample report is
attached .(Click here to see)
• Script can sends us an email message if a process is down.
Choice is yours 
December 15
OR
How to write shell script
December 15
Following steps are required to write shell script:
(1) Use any editor like vi to write shell script.
(2) After writing shell script set execute permission for your
script as follows-
Syntax:
chmod permission your-script-name
Examples:
$ chmod +x your-script-name
$ chmod +x abcd.sh
How to execute your script.
Execute your script as
Syntax:
bash your-script-name
sh your-script-name
ksh your-script-name
./your-script-name
Examples:
$ bash abc.sh
$ sh abc.sh
$ ./abc.sh
December 15
First Script
December 15
Before starting any thing , I will recommend every one to create a Linux Virtual
machine on your laptop/PC . VM will be safe for testing . Do not try any script on
production servers (If you face any difficulty while creating VM , let me know after
this session )
First Script
• Login to your Linux machine, create a test directory
which will hold all of our test scripts.
• In my case, I have created a directory called “test” ,
which will hold my test scripts .
December 15
First Script
• To create a shell script, you use a text editor.
$ vi my_script
• Press “i” to enter in “insert mode” of vi editor
December 15
First Script
• Write logic of your script .
• Press “Esc” key twice to exit from “insert mode”.
• Type :wq! and hit the entre key to save your script
and exit from vi-editor.
• Type “chmod +x my_script” to make it executable.
December 15
Explanation
#!/bin/bash
# My first script
echo "Hello World!"
echo "How are you.“
• The first line of the script is important. This is a special clue given to the
shell indicating what “shell” is used to interpret this script. In this case, it
is /bin/bash.
• The second line is a comment. Everything that appears after a "#" symbol is
ignored by bash.
• The last two lines are echo commands. This command simply prints what it
is given on the display.
December 15
Explanation
December 15
We just covered “echo” command ; It is used to print given text on screen , along with
this you can also use echo command to make Alarm which will makes a BEEP sound, you
can also use echo command to print text in attractive colors.
Since , this session is limited to only introduction , we will learn this options in another
session .
Colored output
Alarm with echo command
How to give your keyboard inputs to script ??
Read command is used to pass your keyboard inputs to script .
• Syntax:
read your-variable-name
• Examples:
$ read my_variable
Now to read the value stored in a variable use “echo” command.
• Syntax:
echo $your-variable-name (Note: “$” before variable name)
• Examples:
$ echo $my_variable
December 15
Second Script
• Now we will make a second script which will ask user
to give some inputs and then it will print those inputs
to screen.
#!/bin/bash
# My second script
echo “What is in your mind…."
read your_input
echo
echo "Your input was : $your_input"
December 15
How to hide your inputs ??
December 15
In the same direction , suppose ,script has asked you to enter your password
and you do not want it to be visible on screen while typing…. In this kind of
situation , everything will be same and you just need to put “-s” (suppress)
option with read command. .
#!/bin/bash
# My 3rd script
echo "Please enter your password"
read -s my_password
echo
echo "Yeah ! i have hacked your password : $my_password"
• In same direction , you can also set a timeout for
users to give there inputs, i.e. if your does not give his
input in given time then , script will stop its execution
after timeout.
• Change command read your_input to read -t 10 your_input in
the 2nd script we made in this session , and see the
difference.
$ read –t time_in_second name_of_varibale
Example read -t 10 abc (timeout after 10 seconds)
December 15
Echo + read = (read –p)
• As we saw in previous 2 scripts , while giving inputs to
script from keyboard we used read and echo
command in pair. We can save one line if use “-p”
(small “P”) with the read command.
$echo “What is in your mind”
$read my_input
$read –p “What is in your mind” my_input
December 15
Feel free to contact me
Akshay Siwal
Email :
akshay231990@gmail.com
December 15
Thank You
December 15

More Related Content

What's hot

Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell scriptBhavesh Padharia
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Zyxware Technologies
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to VimBrandon Liu
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Edureka!
 

What's hot (20)

Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Shell programming
Shell programmingShell programming
Shell programming
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to Vim
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Grep
GrepGrep
Grep
 

Viewers also liked

Advanced penetration testing - Amarendra Godbole
Advanced penetration testing - Amarendra GodboleAdvanced penetration testing - Amarendra Godbole
Advanced penetration testing - Amarendra GodboleIndicThreads
 
Collaboration, Big Data and the search for the Higgs Boson
Collaboration, Big Data and the  search for the Higgs BosonCollaboration, Big Data and the  search for the Higgs Boson
Collaboration, Big Data and the search for the Higgs BosonSuma Pria Tunggal
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash scriptSimon Su
 
Vodafone beta factory - GEC 2015
Vodafone beta factory - GEC 2015Vodafone beta factory - GEC 2015
Vodafone beta factory - GEC 2015Marcello Viti
 
Secure Shell - a Presentation on Ethical Hacking
Secure Shell - a Presentation on Ethical HackingSecure Shell - a Presentation on Ethical Hacking
Secure Shell - a Presentation on Ethical HackingNitish Kasar
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersDavide Ciambelli
 
Introduction to anonymity network tor
Introduction to anonymity network torIntroduction to anonymity network tor
Introduction to anonymity network torKhaled Mosharraf
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
KOHA - Open Source Library Management Software
KOHA - Open Source Library Management SoftwareKOHA - Open Source Library Management Software
KOHA - Open Source Library Management Softwarerajivkumarmca
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Tor the onion router
Tor  the onion routerTor  the onion router
Tor the onion routerAshly Liza
 
Reverse Engineering - Methods and Process
Reverse Engineering - Methods and ProcessReverse Engineering - Methods and Process
Reverse Engineering - Methods and ProcessLa_Lu
 
Cyber security-report-2017
Cyber security-report-2017Cyber security-report-2017
Cyber security-report-2017NRC
 

Viewers also liked (20)

Advanced penetration testing - Amarendra Godbole
Advanced penetration testing - Amarendra GodboleAdvanced penetration testing - Amarendra Godbole
Advanced penetration testing - Amarendra Godbole
 
Collaboration, Big Data and the search for the Higgs Boson
Collaboration, Big Data and the  search for the Higgs BosonCollaboration, Big Data and the  search for the Higgs Boson
Collaboration, Big Data and the search for the Higgs Boson
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Tor Pivoting Networks Share
Tor Pivoting Networks Share Tor Pivoting Networks Share
Tor Pivoting Networks Share
 
Vodafone beta factory - GEC 2015
Vodafone beta factory - GEC 2015Vodafone beta factory - GEC 2015
Vodafone beta factory - GEC 2015
 
Secure Shell - a Presentation on Ethical Hacking
Secure Shell - a Presentation on Ethical HackingSecure Shell - a Presentation on Ethical Hacking
Secure Shell - a Presentation on Ethical Hacking
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 
Introduction to anonymity network tor
Introduction to anonymity network torIntroduction to anonymity network tor
Introduction to anonymity network tor
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Ethical hacking with Python tools
Ethical hacking with Python toolsEthical hacking with Python tools
Ethical hacking with Python tools
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
Open source Library Management Systems
Open source Library Management SystemsOpen source Library Management Systems
Open source Library Management Systems
 
KOHA - Open Source Library Management Software
KOHA - Open Source Library Management SoftwareKOHA - Open Source Library Management Software
KOHA - Open Source Library Management Software
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
How TOR works?
How TOR works?How TOR works?
How TOR works?
 
Bash shell
Bash shellBash shell
Bash shell
 
Tor the onion router
Tor  the onion routerTor  the onion router
Tor the onion router
 
Wireshark Basics
Wireshark BasicsWireshark Basics
Wireshark Basics
 
Reverse Engineering - Methods and Process
Reverse Engineering - Methods and ProcessReverse Engineering - Methods and Process
Reverse Engineering - Methods and Process
 
Cyber security-report-2017
Cyber security-report-2017Cyber security-report-2017
Cyber security-report-2017
 

Similar to Easiest way to start with Shell scripting

Shell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdfShell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdfHIMANKMISHRA2
 
basic shell scripting syntex
basic shell scripting syntexbasic shell scripting syntex
basic shell scripting syntexKsd Che
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxSUBHI7
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cdjacko91
 
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxPart 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxkarlhennesey
 
Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Ahmed El-Arabawy
 
Shell scripting _how_to_automate_command_l_-_jason_cannon
Shell scripting _how_to_automate_command_l_-_jason_cannonShell scripting _how_to_automate_command_l_-_jason_cannon
Shell scripting _how_to_automate_command_l_-_jason_cannonSyed Altaf
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell ScriptAmit Ghosh
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script Amit Ghosh
 
L lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfL lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfhellojdr
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 

Similar to Easiest way to start with Shell scripting (20)

Intro_Unix_Ppt
Intro_Unix_PptIntro_Unix_Ppt
Intro_Unix_Ppt
 
Shell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdfShell Programming_Module2_Part2.pptx.pdf
Shell Programming_Module2_Part2.pptx.pdf
 
Licão 05 scripts exemple
Licão 05 scripts exempleLicão 05 scripts exemple
Licão 05 scripts exemple
 
basic shell scripting syntex
basic shell scripting syntexbasic shell scripting syntex
basic shell scripting syntex
 
60761 linux
60761 linux60761 linux
60761 linux
 
Lab4 scripts
Lab4 scriptsLab4 scripts
Lab4 scripts
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docx
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cd
 
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docxPart 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
Part 4 Scripting and Virtualization (due Week 7)Objectives1. .docx
 
Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell
 
Shell scripting _how_to_automate_command_l_-_jason_cannon
Shell scripting _how_to_automate_command_l_-_jason_cannonShell scripting _how_to_automate_command_l_-_jason_cannon
Shell scripting _how_to_automate_command_l_-_jason_cannon
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell Script
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
dotor.pdf
dotor.pdfdotor.pdf
dotor.pdf
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
L lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfL lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdf
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 

Recently uploaded (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 

Easiest way to start with Shell scripting

  • 1. Shell Scripting (Bash shell only) by - Akshay
  • 2. Agenda In this part of presentation, We will cover… • Introduction to shell programming, • How to read/write/execute a script.
  • 3. Assumptions Before starting with this you should know- • How to use text editor such as vi/vim, • Basic Linux commands. December 15
  • 4. What is SHELL ? December 15 • Shell is just an interface to access an operating system • Shell reads command from user and tells Linux OS what users want.
  • 5. Shell December 15 • Simply, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. • In the old days, Shell was the only user interface available on a Unix/Linux computer. Nowadays, we have GUIs in addition to the shell.
  • 6. Some commands to play with shell December 15 Tip: To find all available shells in your system type following command: $ cat /etc/shells Note that each shell does the same job, but each understand a different command syntax and provides different built-in functions. ****In MS-DOS, Shell name is COMMAND.COM which is also used for same purpose, but it's not as powerful as our Linux Shells are! .
  • 7. What is my current SHELL December 15 Tip: To find your current shell type following command $ echo $SHELL Hint: Bash  which stands for Bourne Again SHell, an enhanced version of the original Bourne shell program, sh, written by Steve Bourne Tip: To find process-id of current shell. $ ps -p $$
  • 8. Further information December 15 To read more information – $man bash $info bash
  • 10. What is Shell Script & Why should I learn scripting ?? December 15 Shell Script basically scripts are collections of commands that are stored in a file. The shell can read this file and act on the commands as if they were typed at the keyboard. We have thousands of commands available for the command line user, Can we remember them all? The answer is, “No”. The real power of the computer is its ability to do the work for you. To get it to do that, we use the power of the shell to automate things. We write scripts.
  • 11. What are scripts good for? December 15 A wide range of tasks can be automated. Here are some of the things I automate with scripts: • On every 1st day of a month, linux-servers backup their configurations and copy it to a “Window/Storage machine“, and delete old backups on successful execution so that we always have latest backup with us. This is performed by a script. • A script on a single click automatically does health check-up on multiple servers and reports the status with colors (Red-> Critical, Yellow-> Warning , Green -> OK) from all servers. A sample report is attached .(Click here to see) • Script can sends us an email message if a process is down.
  • 12. Choice is yours  December 15 OR
  • 13. How to write shell script December 15 Following steps are required to write shell script: (1) Use any editor like vi to write shell script. (2) After writing shell script set execute permission for your script as follows- Syntax: chmod permission your-script-name Examples: $ chmod +x your-script-name $ chmod +x abcd.sh
  • 14. How to execute your script. Execute your script as Syntax: bash your-script-name sh your-script-name ksh your-script-name ./your-script-name Examples: $ bash abc.sh $ sh abc.sh $ ./abc.sh December 15
  • 15. First Script December 15 Before starting any thing , I will recommend every one to create a Linux Virtual machine on your laptop/PC . VM will be safe for testing . Do not try any script on production servers (If you face any difficulty while creating VM , let me know after this session )
  • 16. First Script • Login to your Linux machine, create a test directory which will hold all of our test scripts. • In my case, I have created a directory called “test” , which will hold my test scripts . December 15
  • 17. First Script • To create a shell script, you use a text editor. $ vi my_script • Press “i” to enter in “insert mode” of vi editor December 15
  • 18. First Script • Write logic of your script . • Press “Esc” key twice to exit from “insert mode”. • Type :wq! and hit the entre key to save your script and exit from vi-editor. • Type “chmod +x my_script” to make it executable. December 15
  • 19. Explanation #!/bin/bash # My first script echo "Hello World!" echo "How are you.“ • The first line of the script is important. This is a special clue given to the shell indicating what “shell” is used to interpret this script. In this case, it is /bin/bash. • The second line is a comment. Everything that appears after a "#" symbol is ignored by bash. • The last two lines are echo commands. This command simply prints what it is given on the display. December 15
  • 20. Explanation December 15 We just covered “echo” command ; It is used to print given text on screen , along with this you can also use echo command to make Alarm which will makes a BEEP sound, you can also use echo command to print text in attractive colors. Since , this session is limited to only introduction , we will learn this options in another session . Colored output Alarm with echo command
  • 21. How to give your keyboard inputs to script ?? Read command is used to pass your keyboard inputs to script . • Syntax: read your-variable-name • Examples: $ read my_variable Now to read the value stored in a variable use “echo” command. • Syntax: echo $your-variable-name (Note: “$” before variable name) • Examples: $ echo $my_variable December 15
  • 22. Second Script • Now we will make a second script which will ask user to give some inputs and then it will print those inputs to screen. #!/bin/bash # My second script echo “What is in your mind…." read your_input echo echo "Your input was : $your_input" December 15
  • 23. How to hide your inputs ?? December 15 In the same direction , suppose ,script has asked you to enter your password and you do not want it to be visible on screen while typing…. In this kind of situation , everything will be same and you just need to put “-s” (suppress) option with read command. . #!/bin/bash # My 3rd script echo "Please enter your password" read -s my_password echo echo "Yeah ! i have hacked your password : $my_password"
  • 24. • In same direction , you can also set a timeout for users to give there inputs, i.e. if your does not give his input in given time then , script will stop its execution after timeout. • Change command read your_input to read -t 10 your_input in the 2nd script we made in this session , and see the difference. $ read –t time_in_second name_of_varibale Example read -t 10 abc (timeout after 10 seconds) December 15
  • 25. Echo + read = (read –p) • As we saw in previous 2 scripts , while giving inputs to script from keyboard we used read and echo command in pair. We can save one line if use “-p” (small “P”) with the read command. $echo “What is in your mind” $read my_input $read –p “What is in your mind” my_input December 15
  • 26. Feel free to contact me Akshay Siwal Email : akshay231990@gmail.com December 15

Editor's Notes

  1. Now some of you might be wondering what is so special about shell scripting and why do I have to use it . There are lots of advantages that shell script provide over other programing language…. Some of them are …. Its very convenient and easy to built program in shell and it is even more convenient to debug them . Also there are 1000 of built in or supportive programs like awk , sed etc that make work easier .
  2. If there is complicated task to perform then shell script is a quick and easy way to perform .