SlideShare a Scribd company logo
Shell Automation
 An Introduction to
Bash Shell Scripting
      Anoop John
An Outline
►Shell, interpreter, POSIX
►Shell script operation
►Commands, paths, returns
►Variables, environments
►Input, output, pipes, descriptors
►Expressions, conditions, loops
►Awk, grep, sed, find, xargs
►System utils
►Examples
Shell, Interpreter, POSIX
►Kernel, Shell
►Interprets commands
►Command Line Interpreter / Command Line
Interface
►POSIX compliance
►Sh, Bourne Again, Brian Fox, FSF
Free Software
►Unix
►GNU
►GPL - Four freedoms
 ►Use, Modify, Distribute, Modify &
  Redistribute
►FSF
►GNU / Linux
Shell Operation
►Reads input from file, string (-c), or terminal
►Breaks the input into words and operators
►Parses the tokens into simple and compound
commands
►Performs the various shell expansions
►Performs any necessary redirections
►Executes the command
►Optionally waits for the command to complete
and collects its exit status
Commands
►Executables (ls)
►Shell commands (cd, exit, pwd)
►Return values
►Command input
►Command output
►Path
►Which
Variables & Environment
►Setting a Variable
►Environment (context)
►Script
►Eval
►Exec
►Source .
►Strings, integers, arrays
►Quoting - single, double, escaping
►Global, local
Shell Script
#!/bin/bash
echo “Hello World”;
name=Anoop
echo “Hello $name”
exit;
Arguments & Functions
►Shell Scripts
►Shell Arguments
►Functions
►Function Arguments
Shell Function
function log {
  if [ $# ­gt 0 ]; then
    echo "[$(date +"%D %T")] $@" >> $LOG_FILE
    db "$@"
  else 
    while read data
    do
      echo "[$(date +"%D %T")] $data" >> 
$LOG_FILE 
      db "$data"
    done
  fi
}
log “Hello World!”
echo “Hello World!” | log
Input & Output
►Stdin
►Stdout
►Pipes
►Descriptors
Expressions
►Assignment =
►Arithmetic +, -, *, /, **,
►Bitwise <<, >>, |, &, ~, ^
►Logical !, &&, ||
►Comparisons - Arithmetic -eq, -ne, -lt, -gt, le
►Comparisons - String =, !=, <, >, <=
►Filesystem - -e, -f, -d, -x
If Command
if [[ expression ]] then
  commands;
elif [[ expression ]] then
  commands;
else
  commands;
fi
Case Command
case $ANIMAL in
  horse | dog | cat) 
    echo ­n "four"
    ;;
  man | kangaroo ) 
   echo ­n "two"
   ;;
  *) 
   echo ­n "an unknown number of"
   ;;
esac
For Loop
for NAME [in LIST ]; do 
  COMMANDS; 
done

i=0
for filename in `ls`; do 
  i=$(( i + 1));
  printf "%­5s ­ %sn" $i “$filename”;
done;

for name in Anoop John; do 
  echo “Hello ${name}”;
done;
While Loop
while [[ expression ]]; do 
  COMMANDS; 
done

i=0; while [[ $i ­lt 10 ]]; do
  echo Counting $i;
  ((i+=1));
done;

while read line
do
  echo $line
done < path/to/file
Shell Swiss Army Knives
►awk
►sed
►grep
►find
►xargs
►cat, less, tail, head, watch
Useful Commands
►ps
►top
►kill
►dmesg
►curl, wget
►chown, chmod, chgrp
►uptime, top, nice, nohup
Getting help
►man
►help
►command --help
►Reading scripts
►Mailing lists
►User groups
►Local community
►Search the web
How to Start
►Get GNU / Linux installed on your systems
►Start using shell
►Identify pain points in your daily operations
►Automate through scripts
►Join a mailing list
►Ask & answer questions
►Show off :-)
Exempli Gratia
►Drupal Backups
►Asianet Autologin
►Reliance Autologin
►Secure Shared Folders
About Zyxware
►Free Software Company
►Software Development - Drupal
►Leading Drupal Contributor from India
►FSF Contributing Member
►Free Software Support in the local market
►IT Training and FOSS Enabling
►Websites & Email Services
►IT Consultancy for Enterprises
Thank You!

   www.zyxware.com
  info@zyxware.com
     9446-06-9446

More Related Content

PPTX
Unix shell scripting
PPT
Shell Scripting
PPTX
Presentation of awk
PDF
Shell scripting
PDF
Linux systems - Linux Commands and Shell Scripting
PPT
linux-commands.ppt
PPTX
Unit I - Evaluation of expression
PPTX
DFS and BFS
Unix shell scripting
Shell Scripting
Presentation of awk
Shell scripting
Linux systems - Linux Commands and Shell Scripting
linux-commands.ppt
Unit I - Evaluation of expression
DFS and BFS

What's hot (20)

PDF
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
PDF
Intro to Linux Shell Scripting
PPTX
Bash Shell Scripting
PDF
File management
PPTX
Data structure - Graph
PPT
Introduction to PowerShell
PPT
Data Structure and Algorithms Binary Search Tree
PPT
File system
PPTX
Linux and windows file system
PPTX
Threaded Binary Tree
PPTX
BINARY SEARCH TREE
PDF
Linux basic commands with examples
PPT
Regular Expressions grep and egrep
PDF
Python Debugging Fundamentals
PDF
Part 01 Linux Kernel Compilation (Ubuntu)
PPTX
Device Drivers
PPTX
Database Programming
PPTX
Lex & yacc
PPTX
Stacks in c++
PPTX
stack & queue
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Intro to Linux Shell Scripting
Bash Shell Scripting
File management
Data structure - Graph
Introduction to PowerShell
Data Structure and Algorithms Binary Search Tree
File system
Linux and windows file system
Threaded Binary Tree
BINARY SEARCH TREE
Linux basic commands with examples
Regular Expressions grep and egrep
Python Debugging Fundamentals
Part 01 Linux Kernel Compilation (Ubuntu)
Device Drivers
Database Programming
Lex & yacc
Stacks in c++
stack & queue
Ad

Viewers also liked (6)

PDF
Bash Scripting Workshop
PPTX
Shell Script Tutorial
PDF
Quick start bash script
PDF
Functional Tests Automation with Robot Framework
PDF
Robot Framework Dos And Don'ts
PDF
Robot Framework Introduction
Bash Scripting Workshop
Shell Script Tutorial
Quick start bash script
Functional Tests Automation with Robot Framework
Robot Framework Dos And Don'ts
Robot Framework Introduction
Ad

Similar to Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention, Sep 15, 2012 (20)

PPT
Airlover 20030324 1
PPT
2-introduction_to_shell_scripting
PDF
Module 03 Programming on Linux
PPTX
KT on Bash Script.pptx
PDF
Shell scripting
PPT
Talk Unix Shell Script 1
PPT
Talk Unix Shell Script
PPT
Best training-in-mumbai-shell scripting
DOCX
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
DOCX
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
PPT
Shell scripting - By Vu Duy Tu from eXo Platform SEA
PDF
Unleash your inner console cowboy
PDF
An Intro To ES6
TXT
C99[2]
ODP
Perl one-liners
PPTX
Bash Shell Scripting
PDF
Unit 11 configuring the bash shell – shell script
PPT
Shell programming
PDF
Rakudo
PPT
Best training-in-mumbai-shell scripting
Airlover 20030324 1
2-introduction_to_shell_scripting
Module 03 Programming on Linux
KT on Bash Script.pptx
Shell scripting
Talk Unix Shell Script 1
Talk Unix Shell Script
Best training-in-mumbai-shell scripting
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
Shell scripting - By Vu Duy Tu from eXo Platform SEA
Unleash your inner console cowboy
An Intro To ES6
C99[2]
Perl one-liners
Bash Shell Scripting
Unit 11 configuring the bash shell – shell script
Shell programming
Rakudo
Best training-in-mumbai-shell scripting

More from Zyxware Technologies (20)

PDF
Google Docs - Leverage the power of collaboration with shared documents
PDF
CETAA Vision 2025 - Making CETAA the best alumni association in India
PDF
Learn Drupal 8 Render Pipeline
PDF
Come, build your career at Zyxware Technologies
PDF
Personalized customer experience using ecommerce portal
PDF
Web Application Performance Audit and Optimization
PDF
Drupal is taking over Australia
PDF
Setting in place a product development strategy
PDF
Debugging Drupal - How to Debug your Drupal Application
PDF
Drupal Performance Audit and Optimization
PDF
Drupal as a Rapid Application Development Framework for Non Profits / NGOs
PDF
An introduction to cyber forensics and open source tools in cyber forensics
PDF
Exploring Wider Collaboration Mechanisms in the Drupal Space
PDF
The art of communication - managing digital communication
PDF
Code quality - aesthetics & functionality of writing beautiful code
PDF
Drupal ecosystem in India and Drupal's market potential in India
PDF
Drupal as a Rapid Application Development (RAD) Framework for Startups
ODP
Collaborative development using git, Session conducted at Model Engineering C...
PDF
Introduction to Drupal, Training conducted at MES-AIMAT, Aluva on 2013-09-26
PDF
ICFOSS Interaction with Small and Medium Enterprises on IT Enabling SMEs with...
Google Docs - Leverage the power of collaboration with shared documents
CETAA Vision 2025 - Making CETAA the best alumni association in India
Learn Drupal 8 Render Pipeline
Come, build your career at Zyxware Technologies
Personalized customer experience using ecommerce portal
Web Application Performance Audit and Optimization
Drupal is taking over Australia
Setting in place a product development strategy
Debugging Drupal - How to Debug your Drupal Application
Drupal Performance Audit and Optimization
Drupal as a Rapid Application Development Framework for Non Profits / NGOs
An introduction to cyber forensics and open source tools in cyber forensics
Exploring Wider Collaboration Mechanisms in the Drupal Space
The art of communication - managing digital communication
Code quality - aesthetics & functionality of writing beautiful code
Drupal ecosystem in India and Drupal's market potential in India
Drupal as a Rapid Application Development (RAD) Framework for Startups
Collaborative development using git, Session conducted at Model Engineering C...
Introduction to Drupal, Training conducted at MES-AIMAT, Aluva on 2013-09-26
ICFOSS Interaction with Small and Medium Enterprises on IT Enabling SMEs with...

Recently uploaded (20)

PPTX
Machine Learning_overview_presentation.pptx
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
August Patch Tuesday
PPTX
1. Introduction to Computer Programming.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Mushroom cultivation and it's methods.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine Learning_overview_presentation.pptx
OMC Textile Division Presentation 2021.pptx
Heart disease approach using modified random forest and particle swarm optimi...
Empathic Computing: Creating Shared Understanding
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
August Patch Tuesday
1. Introduction to Computer Programming.pptx
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Getting Started with Data Integration: FME Form 101
cloud_computing_Infrastucture_as_cloud_p
Mushroom cultivation and it's methods.pdf
Unlocking AI with Model Context Protocol (MCP)
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TLE Review Electricity (Electricity).pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention, Sep 15, 2012