SlideShare a Scribd company logo
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

More Related Content

PDF
PDF
Bash in theory and in practice - part two
PDF
Bash in theory and in practice - part one
PDF
Shell scripting
PPT
Unix Shell Scripting Basics
PPT
Unix Shell Scripting Basics
PDF
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
PPTX
Unix shell scripting
Bash in theory and in practice - part two
Bash in theory and in practice - part one
Shell scripting
Unix Shell Scripting Basics
Unix Shell Scripting Basics
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Unix shell scripting

What's hot (20)

PPTX
Unix shell scripting basics
PDF
Introduction to shell scripting
ODP
OpenGurukul : Language : Shell Scripting
PDF
Scripting and the shell in LINUX
PDF
Exploring Code with Pry!
PPT
Unix And Shell Scripting
PDF
Shell scripting
PPT
Shell Scripting
PPTX
Easiest way to start with Shell scripting
PPT
Unix And C
PPT
01 linux basics
PDF
COSCUP2012: How to write a bash script like the python?
PPT
Talk Unix Shell Script
PDF
Shell Script
PDF
Hubot: a look inside our robot friend
PDF
Quick start bash script
PDF
Intro to Linux Shell Scripting
PDF
Vim Script Programming
PPT
Unix Basics
PDF
Beware sharp tools
Unix shell scripting basics
Introduction to shell scripting
OpenGurukul : Language : Shell Scripting
Scripting and the shell in LINUX
Exploring Code with Pry!
Unix And Shell Scripting
Shell scripting
Shell Scripting
Easiest way to start with Shell scripting
Unix And C
01 linux basics
COSCUP2012: How to write a bash script like the python?
Talk Unix Shell Script
Shell Script
Hubot: a look inside our robot friend
Quick start bash script
Intro to Linux Shell Scripting
Vim Script Programming
Unix Basics
Beware sharp tools
Ad

Similar to Bash 4 (20)

PDF
Shell scripting
PDF
One-Liners to Rule Them All
PPTX
KT on Bash Script.pptx
PDF
Lets make better scripts
PDF
Unleash your inner console cowboy
PDF
Plone 3 2: What's New
PDF
Course 102: Lecture 8: Composite Commands
PPTX
Raspberry pi Part 25
PDF
Bash: the #1 skill for Devops Engineers
PDF
BASH Shell Scripting – Part II
ODP
NYPHP March 2009 Presentation
PDF
PDF
2010 Smith Scripting101
TXT
Firewall
PPTX
Licão 05 scripts exemple
PPT
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
PDF
Bash is not a second zone citizen programming language
PDF
Unix Shell Scripting
PDF
DEF CON 23 - Phil Polstra - one device to pwn them all
PDF
Introduction to Linux Kernel Development
Shell scripting
One-Liners to Rule Them All
KT on Bash Script.pptx
Lets make better scripts
Unleash your inner console cowboy
Plone 3 2: What's New
Course 102: Lecture 8: Composite Commands
Raspberry pi Part 25
Bash: the #1 skill for Devops Engineers
BASH Shell Scripting – Part II
NYPHP March 2009 Presentation
2010 Smith Scripting101
Firewall
Licão 05 scripts exemple
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
Bash is not a second zone citizen programming language
Unix Shell Scripting
DEF CON 23 - Phil Polstra - one device to pwn them all
Introduction to Linux Kernel Development
Ad

More from Pieter Colpaert (19)

PDF
Open transport workshop intro slides
PDF
Situation of open data in Flanders
PDF
iRail general info
PDF
iRail: History & current issues
PDF
Project management at iRail Summer of code
PDF
Apps For Flanders
PDF
[Okfn] sncf
PDF
Apps For Flanders at Random Hacks of Kindness
PDF
V-ICT-OR Shopt IT - OKFN Belgium
PDF
Verdediging masterproef
PDF
The DataTank @ weblinks barcamp
PDF
PDF
The DataTank at ogdcamp Warsaw
PDF
iRail summer of code
PDF
Open data with public transport at GentM
PDF
iRail fosdem
PDF
iRail at hack democracy
PDF
iRail meetup
ODP
Free culture
Open transport workshop intro slides
Situation of open data in Flanders
iRail general info
iRail: History & current issues
Project management at iRail Summer of code
Apps For Flanders
[Okfn] sncf
Apps For Flanders at Random Hacks of Kindness
V-ICT-OR Shopt IT - OKFN Belgium
Verdediging masterproef
The DataTank @ weblinks barcamp
The DataTank at ogdcamp Warsaw
iRail summer of code
Open data with public transport at GentM
iRail fosdem
iRail at hack democracy
iRail meetup
Free culture

Recently uploaded (20)

PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PDF
Roadmap Map-digital Banking feature MB,IB,AB
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
Unit 1 Cost Accounting - Cost sheet
PDF
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
PDF
WRN_Investor_Presentation_August 2025.pdf
PDF
Nidhal Samdaie CV - International Business Consultant
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
DOCX
Euro SEO Services 1st 3 General Updates.docx
PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
Laughter Yoga Basic Learning Workshop Manual
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
A Brief Introduction About Julia Allison
PDF
IFRS Notes in your pocket for study all the time
PPTX
Probability Distribution, binomial distribution, poisson distribution
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
COST SHEET- Tender and Quotation unit 2.pdf
Ôn tập tiếng anh trong kinh doanh nâng cao
Roadmap Map-digital Banking feature MB,IB,AB
ICG2025_ICG 6th steering committee 30-8-24.pptx
Unit 1 Cost Accounting - Cost sheet
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
WRN_Investor_Presentation_August 2025.pdf
Nidhal Samdaie CV - International Business Consultant
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Euro SEO Services 1st 3 General Updates.docx
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
unit 1 COST ACCOUNTING AND COST SHEET
340036916-American-Literature-Literary-Period-Overview.ppt
Laughter Yoga Basic Learning Workshop Manual
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
A Brief Introduction About Julia Allison
IFRS Notes in your pocket for study all the time
Probability Distribution, binomial distribution, poisson distribution
Power and position in leadershipDOC-20250808-WA0011..pdf

Bash 4