TEACHERS
GALLERY
PRICING
SIGN IN
TRY ZURU
GET STARTED
Loop
Audio
Interval:
5s
10s
15s
20s
60s
Play
1 of 46
Slide Notes
Download
Go Live
New! Free Haiku Deck for PowerPoint Add-In
Copia di Shell Games <WIP>
Share
Copy
Download
0
59
Slides for a talk I am giving on shell-scripting to the group Women in Linux.
In progress.
View Outline
MORE DECKS TO EXPLORE
PRESENTATION OUTLINE
1.
Shell Games
Shell Scripting for Fun and Profit
2.
CLASS FILES:
github.com/gamefiend/shell-games
3.
Why SHELL Scripting?
The REaL Question: Why Automate?
Photo by
transmediale
4.
Why Automate?
reduce errors.
Save Time.
Eliminate 'Toil'.
...Fun.
5.
Shell SCRIPTING VS the World
*NIX-native Way to perform Actions
Extends Naturally from shell commands
'Just Enough' Programming
6.
Limitations
BASH Syntax is Kinda Garbage
Higher-Order Data Structures Are Cumbersome
painful to debug/troubleshoot
Photo by
JeepersMedia
7.
OVERALL
quick and dirty way to leverage unix tool philosophy
Not a programming replacement
8.
The Philosophy of Unix Tools
9.
It's All About the Pipe
small focused tools chained together for big effect
Photo by
kenmainr
10.
EXERCISE 0
Swiss Army Knives VS Toolboxes
Photo by
herzogbr
11.
Swiss Army Knives VS ToolbOxes
At Shell prompt: info coreutils
/toolbox
on 'Opening the Software Toolbox', hit enter.
12.
Swiss Army Knives Vs Toolboxes, cont.
Scroll down to Toolbox introduction
Read until I/O Redirection
Done!
Let's Discuss
13.
BAsh Scripting
Is a way to use the toolbox, not build Swiss Army Knives.
Photo by
TOMTEC
14.
Foundations
15.
Basics of Shell Scripting
Variables (user, environment, Built-In)
operators
Control Structures (if/THEN, While, For)
functions
16.
Dassit!
But that's All You need
Photo by
Kit4na
17.
EXERCISE 1
encapsulating the cli
Photo by
Bill David Brooks
18.
Encapsulating the CLI (SETUP)
sudo yum install -y git
cd ~/
git clone
https://github.com/gamefiend/shell-games.git
cd shell-games/skels
sudo mv ./* /etc/
19.
Encapsulating the CLI
cd ~/shell-games/exercises
vi ./
useradd-1.sh
20.
useradd-1.sh
21.
Encapsulating the CLI
this script is 'static'
We have to change the script for each new user..
Or do we?
22.
Variables
to the rescue
Photo by
jronaldlee
23.
Encapsulating the CLI
$0 , $1, $X ...
MYVARIABLE='', ${MYVARIABLE}
24.
useradd-1a.sh
25.
Encapsulating the CLI
Variables add flexibility to procedures
Makes one off commands repeatable and generally useful
26.
Exercise 2
Altering the Flow
Photo by
Gustavo Fernando Durán
27.
Altering the Flow
conditionals and control structures
if this, then That
while this happens... do this
for each X in Y...do this
In Case X...do this
28.
Altering the Flow
the power to respond to different input differently.
29.
useradd-2.sh
30.
Altering the Flow
We can prevent or enable actions based on conditions
We can check for problems...
31.
#1 REason to script (IMO)
automate but also sanity check
Photo by
rishibando
32.
useradd-2a.sh
33.
altering the Flow
$? - get exit status code of previous command
you can now make your own skeleton directory for home dir templates.
mkdir /etc/random_skel
We can take one or two parameters as needed.
34.
Exercise 3
Adding more structure
Photo by
scott_steelegreen
35.
Adding More Structure
needing to remember the order and types of the arguments...
Some reminders would help.
36.
Adding More Structure
use $#
use while...do
use case
et voila!
37.
useradd-3.sh
38.
adding more structure
This makes the script easier to come back to
you can ask it for help and it will tell you
seems like a bother, but worth the time.
39.
useradd-3a.sh
40.
Adding More Structure
Functions help you avoid repetition
also help organization
41.
Wrapping UP
Click to add more text here
Photo by
See-ming Lee 李思明 SML
42.
Bash is Suprisingly intricate
but be careful about going too deep
Photo by
Amy Loves Yah
43.
Keep Expanding Tricks
makes cli work more productive
Photo by
Cyol Ternyan
44.
Know when to Quit
Or really, upgrade to higher-level language
Photo by
36Bananapies
45.
Have Fun
shell scripting can be a great party trick.
Photo by
monkeyc.net
46.
Thank YOU!
Questions?
Photo by
Stefan Baudy
Vanni Lusetti
www.riunite.it
×
Error!