SlideShare a Scribd company logo
Bash Scripting

       Prepared by Ahmed Magdy Ezzeldin
File System

●   / is not allowed in a file name
●   file extensions are not important
●   File and folder names are case sensitive
●   Names containing spaces are escaped by  or ""
●   Hidden files start with .
●   Current directory alias . and parent directory alias ..
●   ls, ls -a, ls -l, cp, mv, rm, rm -rdf, ln, ln -sf
Variable and Strings

●   Strings are enclosed in “” '' or just written with spaces escaped
    by 
    VAR=”How are you”
    VAR='How are you'
    VAR=HOW are you
●   Variables
    $VAR
    ${VAR} # e.g. ${FILE}.txt
    echo “my name is $NAME”
    echo “my name is “$NAME
    read VAR
    read VAR1 VAR2
Math

●   echo $((1+1))
●   echo $[1+1]
●   echo `expr 1 + 1`
●   A=$((B*C))
●   let A+=1
●   echo "3.4+7/8-(5.94*3.14)" | bc
File Ownership and Permissions

●   Group and Ownership
    chown, chgrp, ls -l
    chown user:group file
    sudo chown

●   Permissions of files and directories
    chmod 755 file
    chmod +x file
    chmod -x file
                   (r)ead     (w)rite      e(x)ecute

                     4           2            1
Users, su, sudo

●   su, sudo, visudo, /etc/sudoers, su user
●   sudo bash
●   /etc/passwd
●   ~/
Processes and Subshells

●   ps, pgrep, top, jobs, fg, &, kill, signals
●   Sub-shells from :
    ●   Loops
    ●   $()
    ●   Back ticks ``
    ●   bash command
●   /proc
●   fuser
Loops

●   While loop
    while read VAR; do echo $VAR; done
●   For each loop
    for VAR in {1..5}; do echo $VAR; done
    for VAR in 1 2 3 4 5; do echo $VAR; done
    for VAR in {0..10..2}; do echo $VAR; done
    for VAR in $(seq 0 2 10); do echo $VAR; done
●   For loop with counter
    for (( i=0; i<=10; i+=2 )); do echo $i; done
if and switch case

●   If then, else, elif, fi
    if [ -d $F ]; then
        rm -rdf $F
    elif [ -f $F ]; then
        rm $F
    else
        echo “Unknown file type”
    fi
●   case, esac
    while read l; do
     case $l in
      1) echo "One";;
      2) echo "Two";;
      3) echo "Three";;
      *) echo "Invalid"; break;;
     esac
    done
I/O Redirection

●   >, >>, <, &>, 2&>, 2>, |
    echo “error” 1>&2 # redirect std_output to std_err
    some_error_producing_command 2>&1
    some_command &>> log_file_errors_and_output
    some_command >> log_file_output_only
    some_command 2>> log_file_errors_only
    command | filter_command
    command < file
    command > file # truncates and writes into file
    command1 2>&1 | command2
    command1 |& command2
●   Mute by redirecting to /dev/null file
Named Pipes and Network and Signal Processing
●   Network
      exec 9<>/dev/tcp/google.com/80
      echo -e "GET / HTTP/1.0nn" >&9
      while read line <&9; do echo $line; done
●   Named Pipes
      mkfifo pipe
      while read l; do echo $l; done < pipe
      echo “hi” > pipe # on another terminal window
●   Signal Processing
      #!/bin/bash
      function handle_signal () {
         echo "Hi man I got the signal"
      }
      trap "handle_signal; exit" SIGINT
      sleep 100
Cool Stuff and GUI
●   Install these: libnotify-bin, zenity, festival
●   date '+%l oclock' | festival –tts
●   zenity --list --hide-header --text="Are you coming today?" --checklist --column
    "" --column "" FALSE "Yes" FALSE "No" FALSE "May be"
●   zenity --calendar --date-format="%Y/%m/%d"
●   zenity --text="Select Hour" --title="Select Hour" --scale --min-value=0 --max-
    value=24 --value=17
●   zenity --text="Select Minutes" --title="Select Minutes" --scale --min-value=0
    --max-value=59 --value=0
●   zenity --info --text="Did you know this info"
●   zenity --error --text="There is an error"
●   zenity --entry | festival --tts
●   zenity --file-selection
●   <progres command> | zenity --progress --auto-close
●   notify-send -t 10 "hi man" "details"
Launchers

  ● When you drag a file or folder onto a launcher
  it is sent as $1 to the launcher script
Example Codes

●   Bluetooth Obex-push
    NEW_FILE_NAME=`echo $1 | awk -vFS="/" '{print $NF;}'`
    ussp-push 00:22:65:89:22:E6@9 "$1" "$NEW_FILE_NAME"
●   Close the computer when your browser finishes downloading
    your_file
    while true; do sleep 5; if [ -z "`fuser ~/your_file`" ]; then break;
    fi; done; sudo init 0
●   Tell me the time whenever I lock my screen or unlock it
●   Simple spider using curl and wget
●   Log your time easily and report to a Redmine service
●   Think of more ...
Thank you
References


    http://www.linuxcommand.org/lts0040.php

    http://www.cyberciti.biz/faq/bash-for-loop/

       http://linuxcommand.org/wss0160.php

  http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-10.html


 http://wiki.bash-hackers.org/syntax/redirection

  http://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html

More Related Content

What's hot

Comets notes
Comets notesComets notes
Comets notes
Ilija Dukovski
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
vanphp
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
Wim Godden
 
How to send files to remote server via ssh in php
How to send files to remote server via ssh in phpHow to send files to remote server via ssh in php
How to send files to remote server via ssh in php
Andolasoft Inc
 
Unix cheatsheet
Unix cheatsheetUnix cheatsheet
Unix cheatsheet
Dhaval Shukla
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
Ian Barber
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
Ian Barber
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
Ian Barber
 
Clojure + MongoDB on Heroku
Clojure + MongoDB on HerokuClojure + MongoDB on Heroku
Clojure + MongoDB on Heroku
Naoyuki Kakuda
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb
 
Any event intro
Any event introAny event intro
Any event intro
qiang
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
Amaury Bouchard
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
Shell Script
Shell ScriptShell Script
Shell Script
Adam Victor Brandizzi
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Puppet
 
Coming Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsComing Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix Shells
Kel Cecil
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scriptingTony Fabeen
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
Server Density
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
Kirk Kimmel
 
Laporan setting dns
Laporan setting dnsLaporan setting dns
Laporan setting dns
Septian Adi
 

What's hot (20)

Comets notes
Comets notesComets notes
Comets notes
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
How to send files to remote server via ssh in php
How to send files to remote server via ssh in phpHow to send files to remote server via ssh in php
How to send files to remote server via ssh in php
 
Unix cheatsheet
Unix cheatsheetUnix cheatsheet
Unix cheatsheet
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Clojure + MongoDB on Heroku
Clojure + MongoDB on HerokuClojure + MongoDB on Heroku
Clojure + MongoDB on Heroku
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Any event intro
Any event introAny event intro
Any event intro
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Shell Script
Shell ScriptShell Script
Shell Script
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
 
Coming Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsComing Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix Shells
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Laporan setting dns
Laporan setting dnsLaporan setting dns
Laporan setting dns
 

Similar to Bash Scripting Workshop

One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
egypt
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
Aleksandar Bilanovic
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Ashrith Mekala
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
Sanjeev Kumar Jaiswal
 
Mac OSX Terminal 101
Mac OSX Terminal 101Mac OSX Terminal 101
Mac OSX Terminal 101
Murugun Murugun
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
Krasimir Berov (Красимир Беров)
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
Sagar Kumar
 
101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirectsAcácio Oliveira
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
TECHNOLOGY CONTROL CO.
 
Unit 10 investigating and managing
Unit 10 investigating and managingUnit 10 investigating and managing
Unit 10 investigating and managingroot_fibo
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsAbhay Sapru
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsDr.Ravi
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
Michael J Geiser
 
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Vi Grey
 
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
Lubomir Rintel
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
Ben Pope
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
bcoca
 

Similar to Bash Scripting Workshop (20)

One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Mac OSX Terminal 101
Mac OSX Terminal 101Mac OSX Terminal 101
Mac OSX Terminal 101
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
 
101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Unit 10 investigating and managing
Unit 10 investigating and managingUnit 10 investigating and managing
Unit 10 investigating and managing
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
 
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 

More from Ahmed Magdy Ezzeldin, MSc.

Distributed RDBMS: Challenges, Solutions & Trade-offs
Distributed RDBMS: Challenges, Solutions & Trade-offsDistributed RDBMS: Challenges, Solutions & Trade-offs
Distributed RDBMS: Challenges, Solutions & Trade-offs
Ahmed Magdy Ezzeldin, MSc.
 
Win any Interview like a Boss
Win any Interview like a BossWin any Interview like a Boss
Win any Interview like a Boss
Ahmed Magdy Ezzeldin, MSc.
 
Answer Selection and Validation for Arabic Questions
Answer Selection and Validation for Arabic QuestionsAnswer Selection and Validation for Arabic Questions
Answer Selection and Validation for Arabic Questions
Ahmed Magdy Ezzeldin, MSc.
 
Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...
Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...
Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...
Ahmed Magdy Ezzeldin, MSc.
 
A survey of fault prediction using machine learning algorithms
A survey of fault prediction using machine learning algorithmsA survey of fault prediction using machine learning algorithms
A survey of fault prediction using machine learning algorithms
Ahmed Magdy Ezzeldin, MSc.
 
GATE : General Architecture for Text Engineering
GATE : General Architecture for Text EngineeringGATE : General Architecture for Text Engineering
GATE : General Architecture for Text Engineering
Ahmed Magdy Ezzeldin, MSc.
 
Networks and Natural Language Processing
Networks and Natural Language ProcessingNetworks and Natural Language Processing
Networks and Natural Language Processing
Ahmed Magdy Ezzeldin, MSc.
 
Objective C Memory Management
Objective C Memory ManagementObjective C Memory Management
Objective C Memory Management
Ahmed Magdy Ezzeldin, MSc.
 
Object Role Modeling
Object Role ModelingObject Role Modeling
Object Role Modeling
Ahmed Magdy Ezzeldin, MSc.
 

More from Ahmed Magdy Ezzeldin, MSc. (12)

Distributed RDBMS: Challenges, Solutions & Trade-offs
Distributed RDBMS: Challenges, Solutions & Trade-offsDistributed RDBMS: Challenges, Solutions & Trade-offs
Distributed RDBMS: Challenges, Solutions & Trade-offs
 
Win any Interview like a Boss
Win any Interview like a BossWin any Interview like a Boss
Win any Interview like a Boss
 
Answer Selection and Validation for Arabic Questions
Answer Selection and Validation for Arabic QuestionsAnswer Selection and Validation for Arabic Questions
Answer Selection and Validation for Arabic Questions
 
Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...
Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...
Arabic Question Answering: Challenges, Tasks, Approaches, Test-sets, Tools, A...
 
A survey of fault prediction using machine learning algorithms
A survey of fault prediction using machine learning algorithmsA survey of fault prediction using machine learning algorithms
A survey of fault prediction using machine learning algorithms
 
GATE : General Architecture for Text Engineering
GATE : General Architecture for Text EngineeringGATE : General Architecture for Text Engineering
GATE : General Architecture for Text Engineering
 
Networks and Natural Language Processing
Networks and Natural Language ProcessingNetworks and Natural Language Processing
Networks and Natural Language Processing
 
Distributed Coordination-Based Systems
Distributed Coordination-Based SystemsDistributed Coordination-Based Systems
Distributed Coordination-Based Systems
 
Distributed Systems Naming
Distributed Systems NamingDistributed Systems Naming
Distributed Systems Naming
 
Cyclcone a safe dialect of C
Cyclcone a safe dialect of CCyclcone a safe dialect of C
Cyclcone a safe dialect of C
 
Objective C Memory Management
Objective C Memory ManagementObjective C Memory Management
Objective C Memory Management
 
Object Role Modeling
Object Role ModelingObject Role Modeling
Object Role Modeling
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

Bash Scripting Workshop

  • 1. Bash Scripting Prepared by Ahmed Magdy Ezzeldin
  • 2. File System ● / is not allowed in a file name ● file extensions are not important ● File and folder names are case sensitive ● Names containing spaces are escaped by or "" ● Hidden files start with . ● Current directory alias . and parent directory alias .. ● ls, ls -a, ls -l, cp, mv, rm, rm -rdf, ln, ln -sf
  • 3. Variable and Strings ● Strings are enclosed in “” '' or just written with spaces escaped by VAR=”How are you” VAR='How are you' VAR=HOW are you ● Variables $VAR ${VAR} # e.g. ${FILE}.txt echo “my name is $NAME” echo “my name is “$NAME read VAR read VAR1 VAR2
  • 4. Math ● echo $((1+1)) ● echo $[1+1] ● echo `expr 1 + 1` ● A=$((B*C)) ● let A+=1 ● echo "3.4+7/8-(5.94*3.14)" | bc
  • 5. File Ownership and Permissions ● Group and Ownership chown, chgrp, ls -l chown user:group file sudo chown ● Permissions of files and directories chmod 755 file chmod +x file chmod -x file (r)ead (w)rite e(x)ecute 4 2 1
  • 6. Users, su, sudo ● su, sudo, visudo, /etc/sudoers, su user ● sudo bash ● /etc/passwd ● ~/
  • 7. Processes and Subshells ● ps, pgrep, top, jobs, fg, &, kill, signals ● Sub-shells from : ● Loops ● $() ● Back ticks `` ● bash command ● /proc ● fuser
  • 8. Loops ● While loop while read VAR; do echo $VAR; done ● For each loop for VAR in {1..5}; do echo $VAR; done for VAR in 1 2 3 4 5; do echo $VAR; done for VAR in {0..10..2}; do echo $VAR; done for VAR in $(seq 0 2 10); do echo $VAR; done ● For loop with counter for (( i=0; i<=10; i+=2 )); do echo $i; done
  • 9. if and switch case ● If then, else, elif, fi if [ -d $F ]; then rm -rdf $F elif [ -f $F ]; then rm $F else echo “Unknown file type” fi ● case, esac while read l; do case $l in 1) echo "One";; 2) echo "Two";; 3) echo "Three";; *) echo "Invalid"; break;; esac done
  • 10. I/O Redirection ● >, >>, <, &>, 2&>, 2>, | echo “error” 1>&2 # redirect std_output to std_err some_error_producing_command 2>&1 some_command &>> log_file_errors_and_output some_command >> log_file_output_only some_command 2>> log_file_errors_only command | filter_command command < file command > file # truncates and writes into file command1 2>&1 | command2 command1 |& command2 ● Mute by redirecting to /dev/null file
  • 11. Named Pipes and Network and Signal Processing ● Network exec 9<>/dev/tcp/google.com/80 echo -e "GET / HTTP/1.0nn" >&9 while read line <&9; do echo $line; done ● Named Pipes mkfifo pipe while read l; do echo $l; done < pipe echo “hi” > pipe # on another terminal window ● Signal Processing #!/bin/bash function handle_signal () { echo "Hi man I got the signal" } trap "handle_signal; exit" SIGINT sleep 100
  • 12. Cool Stuff and GUI ● Install these: libnotify-bin, zenity, festival ● date '+%l oclock' | festival –tts ● zenity --list --hide-header --text="Are you coming today?" --checklist --column "" --column "" FALSE "Yes" FALSE "No" FALSE "May be" ● zenity --calendar --date-format="%Y/%m/%d" ● zenity --text="Select Hour" --title="Select Hour" --scale --min-value=0 --max- value=24 --value=17 ● zenity --text="Select Minutes" --title="Select Minutes" --scale --min-value=0 --max-value=59 --value=0 ● zenity --info --text="Did you know this info" ● zenity --error --text="There is an error" ● zenity --entry | festival --tts ● zenity --file-selection ● <progres command> | zenity --progress --auto-close ● notify-send -t 10 "hi man" "details"
  • 13. Launchers ● When you drag a file or folder onto a launcher it is sent as $1 to the launcher script
  • 14. Example Codes ● Bluetooth Obex-push NEW_FILE_NAME=`echo $1 | awk -vFS="/" '{print $NF;}'` ussp-push 00:22:65:89:22:E6@9 "$1" "$NEW_FILE_NAME" ● Close the computer when your browser finishes downloading your_file while true; do sleep 5; if [ -z "`fuser ~/your_file`" ]; then break; fi; done; sudo init 0 ● Tell me the time whenever I lock my screen or unlock it ● Simple spider using curl and wget ● Log your time easily and report to a Redmine service ● Think of more ...
  • 16. References http://www.linuxcommand.org/lts0040.php http://www.cyberciti.biz/faq/bash-for-loop/ http://linuxcommand.org/wss0160.php http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-10.html http://wiki.bash-hackers.org/syntax/redirection http://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html