SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Bash       4
Linux Open Administration Days

        Pieter Colpaert_
#Understanding Bash
 >A little history
 >Reinventing UNIX
#Speaking Bash
#Bash 4
#_
Understanding Bash_
A little history (1970)
And some UNIX today (2010)




                   CC BY-SA – Larry Miller
But also
    #Routers
    #Mainframes
    #Servers
    #Smartphones
    #PDA's
    #Toasters
    #..._
Let's reinvent UNIX
/rules/1# Writing software is one thing.
Making it communicate is another_
Let's reinvent UNIX
          #Communication
            >Systemcalls to
             hardware through
             kernel
            >Systemcalls to user
             through a
             scriptinglanguage_
Why Bash?
#Not much knowledge required
#Combines C-shell, Bourne Shell, …
#Free Software
#_
What the hell is wrong with a GUI?
#Nothing
 >For once in a life-time configurations
 >Living today is pretty awesome
#Everything
 >When you have to configure 20 PC's the same way
 >When you don't want to install a demo-version of
    some proprietary tool
  >When you want to do things fast_
Speaking Bash_
Built-in commands

    &, (( )), ., :, [, [[, alias, bg, bind, break, builtin,
  caller, case, cd, command, compgen, complete,
 compopt, continue, coproc, declare, dirs, disown,
 echo, enable, eval, exec, exit, export, false, fc, fg,
for, for, function, getopts, hash, history, if, jobs, kill,
 let, local, logout, mapfile, bind, printf, pushd, pwd,
 read, readarray, readonly, return, set, select, shift,
   shopt, source, suspend, test, time, times, true,
     typeset, ulimit, umask, unalias, unset, until,
              variables, wait, while, { cmd; }
External commands
#Compiled programs
#Bash-scripts
#Alias-commands
#Perl-scripts
#Functions
#_
man-pages
#If you don't know how a command works
  >man command
  >info command
Hello World!
  On stdout:
#echo hello world!
  On stderr:
#echo hello world! >&2
  To a file:
#echo hello world! > HELLOWORLD
  To the end of a file:
#echo hello world! >> HELLOWORLD
Input
###################In script
#read a b c
#set -
 Set your $IFS!
###################From CLI
#Script.sh < file
#Here document:
#script.sh <<EOF
Scripting Basics
#Magic - #!/bin/bash
#Add -x to debug
#Comments - #
#; = EOL
# escapes EOL
#chmod +x
#echo $PATH
Expansion
#VARIABLE=value
 >All-caps not needed, just recommended
#echo ${VARIABLE}
 >{} not always needed, but stops problems
 >$ is necessary
#declare -i VARIABLE=value
 >Specifies variable is an integer
Expansion

#Command Substitution
 >$(command)
 >`command`
#Tilde
 >~ = your home directory
 >~user = user's home directory
#Wildcard globs
 >man 7 glob
Expansion
#Prevention
  > escapes a single special character
  >“” escapes all but $, ` and 
  >'' escapes all special characters
Loops
#for VAR in items in list; do commands; done
#exit status - $?
#test - [ condition ]
#while [ test ]; do commands; done
#until [ test ]; do commands; done
Conditional Statements

#Operators
 >&&
 >||
#if [ test ]; then commands
#elif [ test ]; then commands
#else commands
#fi
Conditional Statements

#case VAR in
 >option)
 >commands
 >;;
 >*)
 >commands
 >;;
 >esac
I/O Redirection

#Combining 1 and 2
 >&>
 >&>>
 >2>&1
 >>&2
#Channel 0 – STDIN
 ><
 >-
User Input
#Arguments
 >$1, $2, ${10}, etc.
 >$* or $@
 >$#
Bash 4_
Bash4
#Associative arrays!
#Expansions ~ perl
#Coproc
#..._
Associative Arrays
#Declare -A array
#array[element]=hello
#echo ${array[element]}
New expansions
  Substring
#${#:0:1}
  Case modification
#${var^^}
#${var^}
#${var,}
#${var,,}
Chopping strings
  Get the extension of the current script
#${0##*.}
#${0#*.} (not correct)
  Get the filename without extension
#${0%.*}
#${0%%.*} (not correct)
Examples
Questions




            #CC BY-SA

Más contenido relacionado

La actualidad más candente

Unix And C
Unix And CUnix And C
Unix And C
Dr.Ravi
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
Lloyd Huang
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
Dr.Ravi
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script Programming
Lin Yo-An
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
Dr.Ravi
 

La actualidad más candente (20)

Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell Scripting
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Exploring Code with Pry!
Exploring Code with Pry!Exploring Code with Pry!
Exploring Code with Pry!
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
Unix And C
Unix And CUnix And C
Unix And C
 
01 linux basics
01 linux basics01 linux basics
01 linux basics
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Shell Script
Shell ScriptShell Script
Shell Script
 
Hubot: a look inside our robot friend
Hubot: a look inside our robot friendHubot: a look inside our robot friend
Hubot: a look inside our robot friend
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Vim Script Programming
Vim Script ProgrammingVim Script Programming
Vim Script Programming
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
Beware sharp tools
Beware sharp toolsBeware sharp tools
Beware sharp tools
 

Similar a Bash 4

Firewall
FirewallFirewall
Firewall
dcs2004
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
Mustafa Qasim
 

Similar a Bash 4 (20)

Shell scripting
Shell scriptingShell scripting
Shell scripting
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
KT on Bash Script.pptx
KT on Bash Script.pptxKT on Bash Script.pptx
KT on Bash Script.pptx
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scripts
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Plone 3 2: What's New
Plone 3 2: What's NewPlone 3 2: What's New
Plone 3 2: What's New
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
Bash: the #1 skill for Devops Engineers
Bash: the #1 skill for Devops EngineersBash: the #1 skill for Devops Engineers
Bash: the #1 skill for Devops Engineers
 
BASH Shell Scripting – Part II
BASH Shell Scripting – Part IIBASH Shell Scripting – Part II
BASH Shell Scripting – Part II
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Slides
SlidesSlides
Slides
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
 
Firewall
FirewallFirewall
Firewall
 
Licão 05 scripts exemple
Licão 05 scripts exempleLicão 05 scripts exemple
Licão 05 scripts exemple
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Bash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageBash is not a second zone citizen programming language
Bash is not a second zone citizen programming language
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
DEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them allDEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them all
 
Introduction to Linux Kernel Development
Introduction to Linux Kernel DevelopmentIntroduction to Linux Kernel Development
Introduction to Linux Kernel Development
 

Más de Pieter Colpaert

Open transport workshop intro slides
Open transport workshop   intro slidesOpen transport workshop   intro slides
Open transport workshop intro slides
Pieter Colpaert
 
Apps For Flanders at Random Hacks of Kindness
Apps For Flanders at Random Hacks of KindnessApps For Flanders at Random Hacks of Kindness
Apps For Flanders at Random Hacks of Kindness
Pieter Colpaert
 
V-ICT-OR Shopt IT - OKFN Belgium
V-ICT-OR Shopt IT - OKFN BelgiumV-ICT-OR Shopt IT - OKFN Belgium
V-ICT-OR Shopt IT - OKFN Belgium
Pieter Colpaert
 
The DataTank at ogdcamp Warsaw
The DataTank at ogdcamp WarsawThe DataTank at ogdcamp Warsaw
The DataTank at ogdcamp Warsaw
Pieter Colpaert
 

Más de Pieter Colpaert (19)

Open transport workshop intro slides
Open transport workshop   intro slidesOpen transport workshop   intro slides
Open transport workshop intro slides
 
Situation of open data in Flanders
Situation of open data in FlandersSituation of open data in Flanders
Situation of open data in Flanders
 
iRail general info
iRail general infoiRail general info
iRail general info
 
iRail: History & current issues
iRail: History & current issuesiRail: History & current issues
iRail: History & current issues
 
Project management at iRail Summer of code
Project management at iRail Summer of codeProject management at iRail Summer of code
Project management at iRail Summer of code
 
Apps For Flanders
Apps For FlandersApps For Flanders
Apps For Flanders
 
[Okfn] sncf
[Okfn] sncf[Okfn] sncf
[Okfn] sncf
 
Apps For Flanders at Random Hacks of Kindness
Apps For Flanders at Random Hacks of KindnessApps For Flanders at Random Hacks of Kindness
Apps For Flanders at Random Hacks of Kindness
 
V-ICT-OR Shopt IT - OKFN Belgium
V-ICT-OR Shopt IT - OKFN BelgiumV-ICT-OR Shopt IT - OKFN Belgium
V-ICT-OR Shopt IT - OKFN Belgium
 
Verdediging masterproef
Verdediging masterproefVerdediging masterproef
Verdediging masterproef
 
The DataTank @ weblinks barcamp
The DataTank @ weblinks barcampThe DataTank @ weblinks barcamp
The DataTank @ weblinks barcamp
 
Creatic
CreaticCreatic
Creatic
 
The DataTank at ogdcamp Warsaw
The DataTank at ogdcamp WarsawThe DataTank at ogdcamp Warsaw
The DataTank at ogdcamp Warsaw
 
iRail summer of code
iRail summer of codeiRail summer of code
iRail summer of code
 
Open data with public transport at GentM
Open data with public transport at GentMOpen data with public transport at GentM
Open data with public transport at GentM
 
iRail fosdem
iRail fosdemiRail fosdem
iRail fosdem
 
iRail at hack democracy
iRail at hack democracyiRail at hack democracy
iRail at hack democracy
 
iRail meetup
iRail meetupiRail meetup
iRail meetup
 
Free culture
Free cultureFree culture
Free culture
 

Último

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Último (20)

John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdf
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 

Bash 4