SlideShare a Scribd company logo
Bash:
The #1 Skill
for DevOps
Engineers
anders.janmyr@ingka.ikea.com
Bash:
The #1 Skill
for DevOps
Engineers
Ugly
and Quirky
But
Powerful and
Everywhere
Bash: Ugly...
Propositions
It's a script.
It's not a server.
Make it work!
Clean it up!
Move on!
Byte-sized :)
Google
Copy-Paste
Learn!
Make it work locally!
Then on CI server.
BAD!
Don't code in YAML!
GOOD!
Code in script.
first.sh
first.sh
Output
first.sh
Takeaways
# First command that reads
STDIN will wait for input.
# Every script has
STDIN, STDOUT, STDERR
Exit status
# Exit status can be used
in conditionals
# STDOUT can be captured
args.sh
args.sh
simple.sh
Takeaways
set -o errexit
# Exits if a command fails
"$1", "$2",...
"$@"
# Always quote args
# Every line executes a
command
'$1'
# No var expansion
Here docs
<<-
Here docs
Takeaways
"$a_var", "$(ls)"
# variable expansion
# cmd execution
$(cat <<-whatever
"Quote": "without escaping"
set -o pipefail
# Exits if a command fails
in pipe
# Great for generating
JSON
Caching
Cache
Takeaways
# Arithmetic
local sum=$(($a + 5))
if (($age > $max_age)); then
# Conditionals
if [[ -f $file ]]; then
// elif/else/fi
# -d (dir)
# Pipes
trace=$(cat $file | grep Akamai)
Functions
Functions
Takeaways
# Call
ret=my_function abc
out=$(my_function abc)
# Vars
"${file?is required}"
"${1?file is required}"
"${1:-default}"
my_function() {
local v="$1"
echo "out $v"
}
tag.sh
tag.sh
Takeaways
# Print line
before executing
[[ "$TRACE" ]] && set -x
# Trim all 'v' from left
new_version=${1##v}
# '%' from right
# Echo to stderr
echoerr() { echo "$@" 1>&2; }
# Command with if
if ! grep $version ./r.md; then
# AWK
awk "/^#.*$new_version/{flag=1;next}/^#/{flag=0}flag" $file
tag.sh
cont.
tag.sh
Takeaways
# Git multiple -m
git commit -am "Release $new_version" -m "$description"
# Git return values
if ! git diff --quiet HEAD; then
# sed
sed -i.bak -E "s/[0-9]+.[0-9]+.[0-9]+/$new_version/g" $file
Trap
Signals
Trap
Signals
cleanup() {
rm -rf $tmp_template
}
trap cleanup EXIT
# Signals
EXIT - Program Exit
SIGINT - Ctrl-C from the keyboard
SIGQUIT - Ctrl- from the keyboard
Useful
Commands
curl, jq,
tr, awk,
...
Watching files
Periodic
execution
When should
I not use
Bash?
Large Programs
> 100 Lines
Complex structures
Maps/Dicts/Structs
Book
Recommendation
Bash:
Questions
anders.janmyr@ingka.ikea.com

More Related Content

PPTX
Lecture 01 Introduction to Software Engineering
PPT
software configuratiom management role n resposnbilities
PDF
PDF
Write your Ruby in Style
PDF
Rocket Fuelled Cucumbers
PDF
Shell scripting
KEY
Rails console
KEY
No comment
Lecture 01 Introduction to Software Engineering
software configuratiom management role n resposnbilities
Write your Ruby in Style
Rocket Fuelled Cucumbers
Shell scripting
Rails console
No comment

Similar to Bash: the #1 skill for Devops Engineers (20)

PDF
Idiot proofing your code
PDF
Quick Intro To JRuby
PDF
Clearly, I Have Made Some Bad Decisions
PDF
One-Liners to Rule Them All
PDF
What we Learned Implementing Puppet at Backstop
PDF
How to deploy node to production
PPTX
Clean Code - The Next Chapter
TXT
Firewall
PDF
Getting things done away from a network
PDF
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
PDF
Shell Programming_Module2_Part2.pptx.pdf
PPTX
Ruby -the wheel Technology
PDF
2012 12-08-travis-ci-could-do
PDF
Pipeline as code for your infrastructure as Code
PDF
Command Line Applications with Ruby
PDF
Automate Yo'self -- SeaGL
PDF
Effective code reviews
PDF
Quines—Programming your way back to where you were
DOCX
CS 112 PA #4Like the previous programming assignment, this assignm.docx
PDF
Testing untestable code - oscon 2012
Idiot proofing your code
Quick Intro To JRuby
Clearly, I Have Made Some Bad Decisions
One-Liners to Rule Them All
What we Learned Implementing Puppet at Backstop
How to deploy node to production
Clean Code - The Next Chapter
Firewall
Getting things done away from a network
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Shell Programming_Module2_Part2.pptx.pdf
Ruby -the wheel Technology
2012 12-08-travis-ci-could-do
Pipeline as code for your infrastructure as Code
Command Line Applications with Ruby
Automate Yo'self -- SeaGL
Effective code reviews
Quines—Programming your way back to where you were
CS 112 PA #4Like the previous programming assignment, this assignm.docx
Testing untestable code - oscon 2012
Ad

Recently uploaded (20)

PDF
Well-logging-methods_new................
PPTX
web development for engineering and engineering
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
DOCX
573137875-Attendance-Management-System-original
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
PPT on Performance Review to get promotions
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Geodesy 1.pptx...............................................
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Welding lecture in detail for understanding
Well-logging-methods_new................
web development for engineering and engineering
Embodied AI: Ushering in the Next Era of Intelligent Systems
Lesson 3_Tessellation.pptx finite Mathematics
CYBER-CRIMES AND SECURITY A guide to understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
573137875-Attendance-Management-System-original
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Foundation to blockchain - A guide to Blockchain Tech
PPT on Performance Review to get promotions
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Geodesy 1.pptx...............................................
Mechanical Engineering MATERIALS Selection
CH1 Production IntroductoryConcepts.pptx
additive manufacturing of ss316l using mig welding
Lecture Notes Electrical Wiring System Components
Welding lecture in detail for understanding
Ad

Bash: the #1 skill for Devops Engineers