1 of 115

Let’s

Learn

Git.

No

Excuses!

@mcdwayne on Twitter

Slides at mcdwayne.com

Bash Is Magic

# No It’s Not

Pantheon.io

2 of 115

Open Source Sales and Marketing since 2005

Founder of�Process Digital Consulting

Some things I enjoy:

  • Crochet
  • Webcomics
  • Karaoke!!!

Slides at: mcdwayne.com

Pantheon.io

3 of 115

https://processdigitalconsulting.com

Turning Strategic Vision Into Tactical Wins

Slides at: mcdwayne.com

Pantheon.io

4 of 115

Poll time

Pantheon.io

5 of 115

How do I get the most from this talk?

  • if you are a novice, just listen and take notes.

  • if you are a casual user, open a terminal and mess around with ideas I am talking about

  • if [[ advanced ]]; then � grep -ir ‘bash unofficial strict mode’ . # go to slide 103

fi

Pantheon.io

6 of 115

Pantheon.io

7 of 115

Pantheon.io

8 of 115

"What Bash does is the point of Open Source. Leveraging smart tools other smart people have built."

--Ben Stoffel-Rosales

Pantheon.io

9 of 115

Pantheon.io

10 of 115

Pantheon.io

11 of 115

Pantheon.io

12 of 115

Pantheon.io

13 of 115

Pantheon.io

14 of 115

Pantheon.io

15 of 115

Using the graphical

user interface

is all you know.

You want to do more

faster.

Pantheon.io

16 of 115

You feel like you are repeating

the same steps

over and over and over and over and over and

over and over and over and over and

over and over and over and over and over and ..

Pantheon.io

17 of 115

“I have a tool for that. Just clone my repo.”�--Every dev on Github

Pantheon.io

18 of 115

Pantheon.io

19 of 115

Pantheon.io

20 of 115

Pantheon.io

21 of 115

Pantheon.io

22 of 115

Pantheon.io

23 of 115

Stephen R. Bourne

Created Unix sh in 1979 at Bell labs

Pantheon.io

24 of 115

In 1988 Richard Stallman and Brian Fox rewrote Bourne’s Shell as the ‘Bourne Again SHell’ under the GNU project

Pantheon.io

25 of 115

Bash is a command processor that typically runs in a text window where the user types commands that cause actions. Bash can also read and execute commands from a file, called a shell script.

Pantheon.io

26 of 115

Bash is a command processor that typically runs in a text window where the user types commands that cause actions. Bash can also read and execute commands from a file, called a shell script.

Pantheon.io

27 of 115

Pantheon.io

28 of 115

Pantheon.io

29 of 115

Pantheon.io

30 of 115

Pantheon.io

31 of 115

Pantheon.io

32 of 115

ADD WINDWS - Linus quote that won

Pantheon.io

33 of 115

Pantheon.io

34 of 115

Pantheon.io

35 of 115

Mac and Linux:

A Bash terminal came included

Windows 10 Professional Edition:�Windows Subsystem for Linux

Other Windows:

Git-Bash

Pantheon.io

36 of 115

Standard Commands

Applications/Tools

Aliases

Scripting and Logic

Pantheon.io

37 of 115

Pantheon.io

38 of 115

The default command line prompt in Mac OS X is something like:

ComputerName:CurrentDirectory User$

�~ = $HOME = default home directory for user

Pantheon.io

39 of 115

Standard Commands

Pantheon.io

40 of 115

pwd

Present Working Directory

“Hey Bash, Show me where I am.”

Pantheon.io

41 of 115

ls

List Directory Contents

“Hey Bash, What’s in this folder?”

Pantheon.io

42 of 115

ls -a

List Directory Contents -All

“Show me everything in the folder?”

Pantheon.io

43 of 115

man [command name]

Display The Manual Pages

“Show me the manual for [command]”

Pantheon.io

44 of 115

cd

Change Directory

“Move into the specified directory”

Pantheon.io

45 of 115

cd ..

Change Directory One Level Up

“Move into the .. directory (one level up)”

Pantheon.io

46 of 115

mkdir

Make A New Directory

“Make me a new folder where I say”

Pantheon.io

47 of 115

cp

Copy

“Make a copy and put it where I say”

Pantheon.io

48 of 115

mv

Move

“Move this to where I say”

Pantheon.io

49 of 115

rm

remove

“Go ahead and forget that thing”

Pantheon.io

50 of 115

rm -rf

Remove file and everything in the file

FORGET THIS FOLDER AND ALL IT CONTAINS!!!”

Pantheon.io

51 of 115

cat

concatenate and print files

“Print the file to the screen”

Pantheon.io

52 of 115

which

locate a program file in the user's path

“Where is the tool actually installed?”

Pantheon.io

53 of 115

history

Show the history of commands

“What did I type to do that?”

Pantheon.io

54 of 115

clear

Clear the screen

“Give me a fresh view for this session”

Pantheon.io

55 of 115

open

Open files and directories

“Let’s open this file or app”

Pantheon.io

56 of 115

Applications/Tools

Pantheon.io

57 of 115

Some are built in (on most systems)

Pantheon.io

58 of 115

grep

file pattern searcher

“Where does this string appear?”

Pantheon.io

59 of 115

curl

transfer a URL

“Go get something from this URL”

Pantheon.io

60 of 115

vi

Vi IMproved, a programmer's text editor

“Edit this file with the default text editor”

Pantheon.io

61 of 115

vi minimal tutorial:

‘i’ to insert to write

‘esc’ to get to Command Mode

‘:wq’ to write & quit �‘:q!’ quit right now without saving

‘man vi’ to read the rest

Pantheon.io

62 of 115

nano

Nano's ANOther editor

“Edit this file with a simpler editor than vi”

Pantheon.io

63 of 115

Many, many more tools you can install

Pantheon.io

64 of 115

Some are installed from Package Managers

Mac (and Linux): Homebrew

https://brew.sh/

Linux: apt-get

Pantheon.io

65 of 115

brew install [package name]

Package manager for macOS

“Install this application on my machine”

Pantheon.io

66 of 115

calc

arbitrary precision calculator

“Do some math for me Bash”

Pantheon.io

67 of 115

git

the stupid content tracker

“Envoke version control”

Pantheon.io

68 of 115

telnet

User interface to the TELNET protocol

“Let me get online with text only”

Pantheon.io

69 of 115

ddgr

DuckDuckGo over the command line

“Search for docs without a browser”

Pantheon.io

70 of 115

Thousands more tools to install per instructions from where you get the code

Pantheon.io

71 of 115

drush

Command line shell for Drupal

“Let me manipulate my Drupal site”

Pantheon.io

72 of 115

wp

The WP-CLI

“Let me manipulate my WordPress site”

Pantheon.io

73 of 115

composer

Dependency Manager for PHP

“Assemble these code files for me”

Pantheon.io

74 of 115

Docksal

All-purpose web-development environment based on Docker

Pantheon.io

75 of 115

behat

Behavior-Driven Development framework

“Did my PHP code change break my site?”

Pantheon.io

76 of 115

backstop

BackstopJS automates visual regression

“How are A’s pixels different than B’s?”

Pantheon.io

77 of 115

AND LITERALLY THOUSANDS MORE...

Pantheon.io

78 of 115

Aliases

Pantheon.io

79 of 115

.bash_profile and .bashrc

aliases

setting environment variables

Pantheon.io

80 of 115

alias term=’phrase term will represent’

Built in tool to alias strings

“When type say this, do that”

Pantheon.io

81 of 115

export PATH=$PATH:$HOME/bin

Path to where executables are located

“When I invoke a tool, find it at this file”

Pantheon.io

82 of 115

source ~/.bash_profile (.bashrc)

Use the changes made in this terminal

“Put those changes into effect now”

Pantheon.io

83 of 115

Scripting

Pantheon.io

84 of 115

Pantheon.io

85 of 115

#!/bin/bash

#! = Shebang

The part after the #! tells the system what program to use to run it.

Pantheon.io

86 of 115

#

# This is a comment and will be ignored

“Don’t execute this line Bash”

Pantheon.io

87 of 115

scriptFileName.sh

.sh is standard file extension

“Bash, run these commands in this order”

Pantheon.io

88 of 115

chmod 755 scriptFileName.sh

change file modes or Access Control Lists

“Let my script be executable”

Pantheon.io

89 of 115

./scriptFileName.sh

./

“Run this script if you can”

Pantheon.io

90 of 115

~/bin/

Local user folder for scripts to run as user

“Wherever I am, run this script by name”

Pantheon.io

91 of 115

Examples

Pantheon.io

92 of 115

Show theme and plugin status on these sites

Pantheon.io

93 of 115

Open these websites in Chrome

Pantheon.io

94 of 115

Make a new post with CSSCMS.club

Pantheon.io

95 of 115

Post content and test it with Behat and BackstopJS before pushing to production

Pantheon.io

96 of 115

Tips and Tricks

Pantheon.io

97 of 115

Pantheon.io

98 of 115

Pantheon.io

99 of 115

Pantheon.io

100 of 115

Pantheon.io

101 of 115

Pantheon.io

102 of 115

Pantheon.io

103 of 115

Pantheon.io

104 of 115

Pantheon.io

105 of 115

Pantheon.io

106 of 115

Pantheon.io

107 of 115

http://redsymbol.net/articles/unofficial-bash-strict-mode/

#!/bin/bash

set -euo pipefail

IFS=$'\n\t'

Pantheon.io

108 of 115

Pantheon.io

109 of 115

Pantheon.io

110 of 115

For everything else!

@mcdwayne

Pantheon.io

111 of 115

ADDD TELEHACK SLIDE

@mcdwayne

Pantheon.io

112 of 115

Official Documents:

https://www.gnu.org/software/bash/manual/

Cheat Sheets!

https://devhints.io/bash

https://learncodethehardway.org/unix/bash_cheat_sheet.pdf

https://www.ullright.org/ullWiki/show/bash-shell-scripting-cheat-sheet

Articles I Like:

https://zwischenzugs.com/2018/01/06/ten-things-i-wish-id-known-about-bash/

https://twitter.com/McDwayne/status/1099046563605733376

"In the Beginning was the Command Line" http://cristal.inria.fr/~weis/info/commandline.html

Bash Cookbook; https://www.amazon.com/bash-Cookbook-Solutions-Examples-Users/dp/1491975334

http://osxdaily.com/2006/12/11/how-to-customize-your-terminal-prompt/

https://ryanstutorials.net/bash-scripting-tutorial/bash-script.php

Advanced:

3 pillars of good bash:

1) google shell style guide - https://google.github.io/styleguide/shell.xml

2) shellcheck - https://www.shellcheck.net/

3) bash unofficial 'strict mode' (`set -eou pipefail`) - http://redsymbol.net/articles/unofficial-bash-strict-mode/

1000s of ‘how to’ guides, docs and articles

@mcdwayne

Pantheon.io

113 of 115

Pantheon.io

114 of 115

Open Source Sales and Marketing since 2005

Founder of�Process Digital Consulting

Some things I enjoy:

  • Crochet
  • Webcomics
  • Karaoke!!!

Slides at: mcdwayne.com

Pantheon.io

115 of 115

dwayne@processdigitalconsulting.com

@mcdwayne on Twitter

Slides at: mcdwayne.com

Q & A

Pantheon.io