Thanks and wrap up

Introduction to Bash Scripting

Alex Scriven

Data Scientist

What we covered (Chapter 1)

Chapter 1 - The basics:

  • How Bash scripts work with the command-line
  • The anatomy of a Bash script
    • Including STDIN, STDERR and STDOUT

STDIN STDOUT Graphically

Introduction to Bash Scripting

Chapter 1 - ARGV

ARGV is the array of all the arguments given to the program. ARGV is vital knowledge.

  • Some special properties we learned:
    • Each argument can be accessed via the $ notation. ($1, $2 etc.)
    • $@ (and $*) return all the arguments in ARGV
    • $# gives the length (number) of arguments

In an example script.sh:

#!/usr/bash
echo $1
echo $@

Call with bash script.sh FirstArg SecondArg

FirstArg
FirstAg SecondArg
Introduction to Bash Scripting

What we covered (Chapter 2)

You learned about creating and using different Bash variables including:

  • Creating and using both string, numerical and array variables
    • Arithmetic using expr and (for decimals) bc
  • Different quotation marks mean different things:
    • Single (interpret all text literally)
    • And double ( interpret literally except $ and backticks)
Introduction to Bash Scripting

Chapter 2 - Shell-within-a-shell

A concept we used again and again (and again!) was the shell-within-a-shell.

  • Very powerful concept; calling out to a shell in-place within a script and getting the return value.
sum=$(expr 4 + 5)
echo $sum
9
Introduction to Bash Scripting

What we covered (Chapters 3 & 4)

 

Mastering control of your scripts with:

  • FOR, WHILE, CASE, IF statements
  • Creating functions, calling them and pushing data in (arguments) and out (return values)
  • Scheduling your scripts with cron so you don't need to remember to run another script!
Introduction to Bash Scripting

Thank you & Congratulations!

Introduction to Bash Scripting

Preparing Video For Download...