SlideShare a Scribd company logo
1 of 40
Download to read offline
Unleash your inner
console cowboy
Kenneth Geisshirt
kg@realm.io
Realm Inc.
@realm
http://github.com/Realm/
http://realm.io/
Ivan Constantin, https://www.flickr.com/photos/ivan70s/
Today’s goal
• Present bash as a productivity tool
• stop using the mouse 🐁
• Write scripts to automate your work
• Begin to use advanced tools in your daily work
Become a console cowboy
Agenda
• The terminal and the
shell
• Basic usage of bash
• Living on the
command-line
• Useful utilities
• Scripting
• Home brew
• Tools for developers
• git
• Xcode
The shell
Which terminal?
• iTerm2 is much better
• Easier to change tab (⌘ left
+ right, CTRL+TAB)
• Change Desktop navigation
to ⌥ left + right
• Add CTRL left + right to
iTerm2 preferences
• Keeps SSH connection alive
• http://iterm2.com/
Which shell?
OS X comes with many shells
➤ bash, csh, ksh, sh, tcsh, and zsh
Parée, https://www.flickr.com/photos/pareeerica/
Since 10.3, bash has been the default shell
OS X 10.11.1 carries bash 3.2.57 (2014-11-07)
Stephen R. Bourne (Bell lab) introduced the
shell to UNIX in 1977
Home brew has many great bash related packages
Redirection
UNIX idioms
• a tool should do one thing
but do it well
• text is the universal data
format
}Output of one utility is input for the next
Bash implements redirection:
• stdout to file: >
• stdin from file <
• append stdout to file: >>
• stderr to stdout: 2>&1
Examples:
echo “Hello” > hello
cat < hello
echo “World” >> hello
clang notfound.m > error 2>&1
Pipes
• Introduced to UNIX by Douglas
McIlroy in 1973
• Pipes are the glue in UNIX
component based programming (aka
shell scripting)
• Powerful idiom for stream processing
• The character | is used by all known
shells
Examples
lsof | grep ^Keynote | wc -l
ifconfig | grep -e ^[a-z] | cut -f1 -d:
"Pipeline" by TyIzaeL - Licensed under Public domain via Wikimedia Commons
http://commons.wikimedia.org/wiki/File:Pipeline.svg#mediaviewer/File:Pipeline.svg
Configuration
• $HOME/.bash_profile and $HOME/.bashrc
are your personal configuration
• alias - useful for often used options
• Setting prompt (PS1) and search path (PATH)
• Reload configuration: source ~/.bash_profile
.bash_profile
# Ignore a few commands in history
export HISTIGNORE="pwd:ls:ls -l:cd"
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups
# Bash completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# Prompt - including git
PS1='u@h:w$(__git_ps1 " (%s)") $ ‘
# Color ls etc.
alias ls="ls -G"
alias ll="ls -l"
# https://xkcd.com/149/
alias fuck='sudo $(history -p !!)' # rerun as root
Keyboard short-cuts
• Bash uses Emacs bindings by default 😄
(help bind for details)
Movement
• CTRL-a beginning of line
• CTRL-e end of line
• CTRL-← One word left
• CTRL-→ One word right
Cut-n-paste
• CTRL-space mark
• 🔙 Delete word
• CTRL-d Delete character
• CTRL-_ undo
• CTRL-k delete until end
of line
• CTRL-y yank from kill-
ring
Remap CTRL-←/→
History
• Bash stores your command history
• history - show latest commands
• !! - run last command
• !number - run command number again
• CTRL-r - search in history
• Exclude commands from history:
• export HISTIGNORE=“pwd:ls:ls -l:cd”
• Exclude duplicates from history:
• export HISTCONTROL:ignoredups
Completion
• Use TAB to let Bash complete as much as possible
• Use TAB+TAB to show possible completions
• Bash has programmable completion → you can
specify what Bash does
• Large collections of completion recipes exist (home
brew is your friend)
Living on the command-line
• cd - - go back to previous folder
• file file - guess file content (magic numbers)
• lsof - list open files
• ps (aux or -ef) and top - show processes
• Simple watch:
while true ; do clear ; command ; sleep
n ; done
OS X specific commands
• open file - Starts registered program and open file
• say “Hello world” - speech synthesis (download
extra voices/languages in System preferences)
• ls | pbcopy - copy stdin to paste board
• pbpaste - paste to stdout
• dns-sd -B _ssh._tcp - show Bonjour enabled SSH
hosts
Useful utilities
Find files: find . -name ‘*.o’ -delete
Patterns: grep -r list *
Cut field: cut -f1,3 -d: /etc/passwd
Word count: wc -l *.cpp
Transform: tr “ “ “_” < README.org
Sort lines: sort -t: -n -r -k 4 /etc/passwd
Last lines: tail /etc/passwd
First lines: head /etc/passwd
sed - the stream editor
• sed is used to edit files non-
interactively
• Option -E gives an editing (regular)
expression
• s/FISH/HORSE/g - substitute
• /FISH/d - delete lines
joinash, https://www.flickr.com/photos/joinash/
Option -i is tricky:
• GNU sed has optional extension
• BSD sed requires extension (‘’ is useful)
awk - a processing tool
• awk is a programming
language by itself
• Matching lines are
processed
• line is split in fields
(spaces are default)
Patterns:
BEGIN - before opening file
END - after closing file
A. Aho, P. Weinberger, B. Kernighan
cat foo | awk 'BEGIN {total=0 } END { print total } { total+=$1 }'
Scripting
Bash for programmers
• Bash is a complete programming language
• Shell scripts grow and become ugly 😞
• Execution:
• sh script.sh
• chmod +x script.sh; ./script.sh
• Interpreted language → slow
Basic syntax
• White spaces: space and
tab
• Comments: # and to end-
of-line
• Statements: either end-
of-line of ; (semicolon)
• Variables and functions:
Letters, digits and
underscore
#!/bin/bash
# Monte Carlo calculation of pi
NSTEPS=500
NHITS=0
i=0
while [ $i -lt $NSTEPS ]; do
x=$(echo $RANDOM/32767 | bc -l)
y=$(echo $RANDOM/32767 | bc -l)
d=$(echo "sqrt($x*$x+$y*$y) < 1.0" | bc -l)
if [ $d -eq 1 ]; then
NHITS=$(($NHITS + 1))
fi
i=$(($i + 1))
done
PI=$(echo "4.0*$NHITS/$NSTEPS" | bc -l)
echo "PI = $PI"
Variables• Case-sensitive names
• No declarations, no types
• Strings: “…” are substituted; ‘…’ are not
• Assignment (=): no spaces!
• $(…) assignment from stdout
including spaces
• I often use awk ‘{print $1}’ to
remove spaces
• $((…)) arithmetic
• $varname - value of variable varname
Built-in variables:
• $# is the number of argument
• $1, $2, … are the arguments
• $$ is the process ID
• $? is exit code of last command
#!/bin/bash
message_1="Hello"
message_2="World"
message="$message_1 $message_2” # concatenate
echo $message
# assign with output of command
nusers=$(grep -v ^# /etc/passwd | wc -l | awk
'{print $1}')
echo "Number of users: $nusers"
# do the math
answer=$((6*7))
echo "The life, the universe, and everything:
$answer"
Branches
• Simple branching with if then
else fi
• Enclose condition with []
• elif is possible, too
• Use case in esac when you
can many cases and single
condition
String operators:
-z is empty?
-d is directory?
-f is file?
== equal to
!= not equal to
Integer operators:
-eq equal to
-lt less than
-ne not equal to
-gt greater than
branches.sh
#!/bin/bash
if [ -z "$1" ]; then
name="Arthur"
else
name="$1"
fi
if [ "$name" != "Arthur" ]; then
echo "Not Arthur"
else
echo "Hello Arthur"
fi
answer=$((6*7))
if [ $answer -eq 42 ]; then
echo "Life, the universe, and everything"
fi
branches.sh - con’t
case "$name" in
"Arthur")
echo "Welcome onboard"
;;
"Trillian")
echo "You know Arthur"
;;
*)
echo "Who are you?"
;;
esac
Loops
• Simple loops: for … in … ; do …
done
• The seq utility can generate list of
numbers
• Conditional loops: while … ; do …
done
• Line-by-line: while read line ;
do … done
One-liner (similar to watch)
while [ true ]; do
clear;
echo $RANDOM;
sleep 1;
done
loops.sh#!/bin/bash
# Multiplication table
for i in $(seq 1 10); do
echo "$i $((3*$i))"
done
# All .sh files
for f in $(ls *.sh); do
echo "$f $(head -1 $f | cut -c3-) $(wc -l $f | awk '{print $1}')"
done
# read self line-by-line
i=1
cat $0 | while read line ; do
nchars=$(echo "$line" | wc -c | awk '{print $1}')
echo "$i $nchars"
i=$(($i+1))
done | sort -n -k 2
Functions
• Functions can increase readability of your scripts
• arguments are $1, $2, …
• local variables can be used
• return an integer and get it as $?
• Use global variable to return a string 😒
function.sh
#!/bin/bash
mult () {
local n=$1
return $((3*$n))
}
for n in $(seq 1 10); do
mult $n
echo "$n $?”
done
Tips and tricks
• Use set -e to exit early
• or use || exit 1
• set -O pipefail and you can get the exit code of the
first failing program in a pipe
• xcpretty never fails but xcodebuild might
• Use tee to write to stdout and file
• To trace (debugging): set -x or sh -x
Tips and tricks
• Always use “$var” when dealing with file names (and strings)
• str=“fish horse”; for i in $str; do echo $i; done
• str=“fish horse”; for i in “$str”; do echo $i; done
• Call mkdir -p when creating folders
• Create temp. files with mktemp /tmp/$$.XXXXXX
• Using variable to modify behaviour of script:
• FLAGS=“-O3 -libc++=stdlibc++” build.sh
• Subshells: (cd foo && rm -f bar)
Tool for
developers
Home brew
• Home brew provides calories for
console cowboys
• You don’t have to be root to install
• Software is installed in /usr/
local/Cellar, and symlinked to /
usr/local/bin
• Brew cask is for binary distribution
• http://brew.sh and http://
caskroom.io
Greg Peverill-Conti, https://www.flickr.com/photos/gregpc/
Examples:
brew search bash
brew info bash
brew install bash
brew update
Tools for developers
• Apple provides some basic tools
• nm - display symbol table
• c++filt - Prettify C++ and Java names
• otool -L - display which shared libraries are
required
• libtool - create libraries
• lipo - manipulate fat/universal binaries
zzpza, https://www.flickr.com/photos/zzpza/
Examples:
nm book.o | c++filt
otool -L RealmInspector
git
• Home brew packages:
• git, git-extras
• Symlink /usr/local/bin/git to /
usr/bin
• Bash completion works
• commands, branches, etc.
• Fancy prompt:
PS1='u@h:w$(__git_ps1 " (%s)") $ ‘
git log --graph --simplify-by-decoration --pretty=format:'%d' --all
Examples:
git count -all
git contrib "Kenneth Geisshirt"
Xcode
• You can build Xcode projects at the
command-line
xcodebuild -scheme OreDevPlain -
configuration Release -sdk
iphonesimulator
• Targets: clean, build, test
• You can add shell scripts to build phases
xcpretty
• The output of xcodebuild can be hard to read
• xcpretty makes it prettier
• Installation:
• sudo gem install xcpretty
• Usage:
• xbuildcode … | xcpretty
xctool
• Yet another build helper
• Installation:
• brew install xctool
• Usage:
• xctool -scheme OredevPlain -
configuration Release -sdk
iphonesimulator build
Further information
• Classical Shell Scripting. R. Arnolds and N.H.F.
Beebe. O’Reilly Media, 2005.
• The sed FAQ: http://sed.sourceforge.net/
sedfaq.html
• Advanced Bash-Scripting Guide: http://
www.tldp.org/LDP/abs/html/
http://realm
.io
W
e
are
hiring

More Related Content

What's hot

Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopSages
 
Ts archiving
Ts   archivingTs   archiving
Ts archivingConfiz
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
Python在豆瓣的应用
Python在豆瓣的应用Python在豆瓣的应用
Python在豆瓣的应用Qiangning Hong
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by exampleYunWon Jeong
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architectureJung Kim
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)Qiangning Hong
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Jung Kim
 
All you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopSaša Tatar
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos WengerAmos Wenger
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceAlexander Gladysh
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in GroovyJim Driscoll
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesJamund Ferguson
 

What's hot (20)

Python Objects
Python ObjectsPython Objects
Python Objects
 
Wprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache HadoopWprowadzenie do technologi Big Data i Apache Hadoop
Wprowadzenie do technologi Big Data i Apache Hadoop
 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
Python在豆瓣的应用
Python在豆瓣的应用Python在豆瓣的应用
Python在豆瓣的应用
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
 
All you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loop
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing Experience
 
Turtle Graphics in Groovy
Turtle Graphics in GroovyTurtle Graphics in Groovy
Turtle Graphics in Groovy
 
JavaScript on the GPU
JavaScript on the GPUJavaScript on the GPU
JavaScript on the GPU
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 

Similar to Unleash your inner console cowboy

Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
Bash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageBash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageRené Ribaud
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them Allegypt
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foobrian_dailey
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsManav Prasad
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsSudharsan S
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introductionthasso23
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsAbhay Sapru
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsDr.Ravi
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cdjacko91
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scriptsMichael Boelen
 
Geecon 2019 - Taming Code Quality in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality  in the Worst Language I Know: BashGeecon 2019 - Taming Code Quality  in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality in the Worst Language I Know: BashMichał Kordas
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 

Similar to Unleash your inner console cowboy (20)

Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Bash shell
Bash shellBash shell
Bash shell
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Bash is not a second zone citizen programming language
Bash is not a second zone citizen programming languageBash is not a second zone citizen programming language
Bash is not a second zone citizen programming language
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introduction
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cd
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scripts
 
Geecon 2019 - Taming Code Quality in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality  in the Worst Language I Know: BashGeecon 2019 - Taming Code Quality  in the Worst Language I Know: Bash
Geecon 2019 - Taming Code Quality in the Worst Language I Know: Bash
 
Slides
SlidesSlides
Slides
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 

More from Kenneth Geisshirt

Building parsers in JavaScript
Building parsers in JavaScriptBuilding parsers in JavaScript
Building parsers in JavaScriptKenneth Geisshirt
 
Building mobile apps with Realm for React Native
Building mobile apps with Realm for React NativeBuilding mobile apps with Realm for React Native
Building mobile apps with Realm for React NativeKenneth Geisshirt
 
Tales from the dark side: developing SDKs at scale
Tales from the dark side: developing SDKs at scaleTales from the dark side: developing SDKs at scale
Tales from the dark side: developing SDKs at scaleKenneth Geisshirt
 
Tips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeKenneth Geisshirt
 
Is the database a solved problem?
Is the database a solved problem?Is the database a solved problem?
Is the database a solved problem?Kenneth Geisshirt
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Kenneth Geisshirt
 
Naturvidenskabsfestival 2012
Naturvidenskabsfestival 2012Naturvidenskabsfestival 2012
Naturvidenskabsfestival 2012Kenneth Geisshirt
 
Hadoop - the data scientist's toolbox
Hadoop - the data scientist's toolboxHadoop - the data scientist's toolbox
Hadoop - the data scientist's toolboxKenneth Geisshirt
 
JavaScript/Emacs integration
JavaScript/Emacs integrationJavaScript/Emacs integration
JavaScript/Emacs integrationKenneth Geisshirt
 
Introduction to JavaScript for Modern Software Development
Introduction to JavaScript for Modern Software DevelopmentIntroduction to JavaScript for Modern Software Development
Introduction to JavaScript for Modern Software DevelopmentKenneth Geisshirt
 

More from Kenneth Geisshirt (17)

Building parsers in JavaScript
Building parsers in JavaScriptBuilding parsers in JavaScript
Building parsers in JavaScript
 
Open Source in Real Life
Open Source in Real LifeOpen Source in Real Life
Open Source in Real Life
 
Building mobile apps with Realm for React Native
Building mobile apps with Realm for React NativeBuilding mobile apps with Realm for React Native
Building mobile apps with Realm for React Native
 
micro:bit and JavaScript
micro:bit and JavaScriptmicro:bit and JavaScript
micro:bit and JavaScript
 
Tales from the dark side: developing SDKs at scale
Tales from the dark side: developing SDKs at scaleTales from the dark side: developing SDKs at scale
Tales from the dark side: developing SDKs at scale
 
Android things
Android thingsAndroid things
Android things
 
Node.js extensions in C++
Node.js extensions in C++Node.js extensions in C++
Node.js extensions in C++
 
Tips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native code
 
Is the database a solved problem?
Is the database a solved problem?Is the database a solved problem?
Is the database a solved problem?
 
Extending Node.js using C++
Extending Node.js using C++Extending Node.js using C++
Extending Node.js using C++
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
Sociale netværk
Sociale netværkSociale netværk
Sociale netværk
 
Naturvidenskabsfestival 2012
Naturvidenskabsfestival 2012Naturvidenskabsfestival 2012
Naturvidenskabsfestival 2012
 
Hadoop - the data scientist's toolbox
Hadoop - the data scientist's toolboxHadoop - the data scientist's toolbox
Hadoop - the data scientist's toolbox
 
JavaScript/Emacs integration
JavaScript/Emacs integrationJavaScript/Emacs integration
JavaScript/Emacs integration
 
Introduction to JavaScript for Modern Software Development
Introduction to JavaScript for Modern Software DevelopmentIntroduction to JavaScript for Modern Software Development
Introduction to JavaScript for Modern Software Development
 
Kendthed og vigtighed
Kendthed og vigtighedKendthed og vigtighed
Kendthed og vigtighed
 

Recently uploaded

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 

Recently uploaded (20)

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 

Unleash your inner console cowboy

  • 1. Unleash your inner console cowboy Kenneth Geisshirt kg@realm.io Realm Inc. @realm http://github.com/Realm/ http://realm.io/ Ivan Constantin, https://www.flickr.com/photos/ivan70s/
  • 2. Today’s goal • Present bash as a productivity tool • stop using the mouse 🐁 • Write scripts to automate your work • Begin to use advanced tools in your daily work Become a console cowboy
  • 3. Agenda • The terminal and the shell • Basic usage of bash • Living on the command-line • Useful utilities • Scripting • Home brew • Tools for developers • git • Xcode
  • 5. Which terminal? • iTerm2 is much better • Easier to change tab (⌘ left + right, CTRL+TAB) • Change Desktop navigation to ⌥ left + right • Add CTRL left + right to iTerm2 preferences • Keeps SSH connection alive • http://iterm2.com/
  • 6. Which shell? OS X comes with many shells ➤ bash, csh, ksh, sh, tcsh, and zsh Parée, https://www.flickr.com/photos/pareeerica/ Since 10.3, bash has been the default shell OS X 10.11.1 carries bash 3.2.57 (2014-11-07) Stephen R. Bourne (Bell lab) introduced the shell to UNIX in 1977 Home brew has many great bash related packages
  • 7. Redirection UNIX idioms • a tool should do one thing but do it well • text is the universal data format }Output of one utility is input for the next Bash implements redirection: • stdout to file: > • stdin from file < • append stdout to file: >> • stderr to stdout: 2>&1 Examples: echo “Hello” > hello cat < hello echo “World” >> hello clang notfound.m > error 2>&1
  • 8. Pipes • Introduced to UNIX by Douglas McIlroy in 1973 • Pipes are the glue in UNIX component based programming (aka shell scripting) • Powerful idiom for stream processing • The character | is used by all known shells Examples lsof | grep ^Keynote | wc -l ifconfig | grep -e ^[a-z] | cut -f1 -d: "Pipeline" by TyIzaeL - Licensed under Public domain via Wikimedia Commons http://commons.wikimedia.org/wiki/File:Pipeline.svg#mediaviewer/File:Pipeline.svg
  • 9. Configuration • $HOME/.bash_profile and $HOME/.bashrc are your personal configuration • alias - useful for often used options • Setting prompt (PS1) and search path (PATH) • Reload configuration: source ~/.bash_profile
  • 10. .bash_profile # Ignore a few commands in history export HISTIGNORE="pwd:ls:ls -l:cd" # don't put duplicate lines in the history. See bash(1) for more options # don't overwrite GNU Midnight Commander's setting of `ignorespace'. HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups # Bash completion if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi # Prompt - including git PS1='u@h:w$(__git_ps1 " (%s)") $ ‘ # Color ls etc. alias ls="ls -G" alias ll="ls -l" # https://xkcd.com/149/ alias fuck='sudo $(history -p !!)' # rerun as root
  • 11. Keyboard short-cuts • Bash uses Emacs bindings by default 😄 (help bind for details) Movement • CTRL-a beginning of line • CTRL-e end of line • CTRL-← One word left • CTRL-→ One word right Cut-n-paste • CTRL-space mark • 🔙 Delete word • CTRL-d Delete character • CTRL-_ undo • CTRL-k delete until end of line • CTRL-y yank from kill- ring Remap CTRL-←/→
  • 12. History • Bash stores your command history • history - show latest commands • !! - run last command • !number - run command number again • CTRL-r - search in history • Exclude commands from history: • export HISTIGNORE=“pwd:ls:ls -l:cd” • Exclude duplicates from history: • export HISTCONTROL:ignoredups
  • 13. Completion • Use TAB to let Bash complete as much as possible • Use TAB+TAB to show possible completions • Bash has programmable completion → you can specify what Bash does • Large collections of completion recipes exist (home brew is your friend)
  • 14. Living on the command-line • cd - - go back to previous folder • file file - guess file content (magic numbers) • lsof - list open files • ps (aux or -ef) and top - show processes • Simple watch: while true ; do clear ; command ; sleep n ; done
  • 15. OS X specific commands • open file - Starts registered program and open file • say “Hello world” - speech synthesis (download extra voices/languages in System preferences) • ls | pbcopy - copy stdin to paste board • pbpaste - paste to stdout • dns-sd -B _ssh._tcp - show Bonjour enabled SSH hosts
  • 16. Useful utilities Find files: find . -name ‘*.o’ -delete Patterns: grep -r list * Cut field: cut -f1,3 -d: /etc/passwd Word count: wc -l *.cpp Transform: tr “ “ “_” < README.org Sort lines: sort -t: -n -r -k 4 /etc/passwd Last lines: tail /etc/passwd First lines: head /etc/passwd
  • 17. sed - the stream editor • sed is used to edit files non- interactively • Option -E gives an editing (regular) expression • s/FISH/HORSE/g - substitute • /FISH/d - delete lines joinash, https://www.flickr.com/photos/joinash/ Option -i is tricky: • GNU sed has optional extension • BSD sed requires extension (‘’ is useful)
  • 18. awk - a processing tool • awk is a programming language by itself • Matching lines are processed • line is split in fields (spaces are default) Patterns: BEGIN - before opening file END - after closing file A. Aho, P. Weinberger, B. Kernighan cat foo | awk 'BEGIN {total=0 } END { print total } { total+=$1 }'
  • 20. Bash for programmers • Bash is a complete programming language • Shell scripts grow and become ugly 😞 • Execution: • sh script.sh • chmod +x script.sh; ./script.sh • Interpreted language → slow
  • 21. Basic syntax • White spaces: space and tab • Comments: # and to end- of-line • Statements: either end- of-line of ; (semicolon) • Variables and functions: Letters, digits and underscore #!/bin/bash # Monte Carlo calculation of pi NSTEPS=500 NHITS=0 i=0 while [ $i -lt $NSTEPS ]; do x=$(echo $RANDOM/32767 | bc -l) y=$(echo $RANDOM/32767 | bc -l) d=$(echo "sqrt($x*$x+$y*$y) < 1.0" | bc -l) if [ $d -eq 1 ]; then NHITS=$(($NHITS + 1)) fi i=$(($i + 1)) done PI=$(echo "4.0*$NHITS/$NSTEPS" | bc -l) echo "PI = $PI"
  • 22. Variables• Case-sensitive names • No declarations, no types • Strings: “…” are substituted; ‘…’ are not • Assignment (=): no spaces! • $(…) assignment from stdout including spaces • I often use awk ‘{print $1}’ to remove spaces • $((…)) arithmetic • $varname - value of variable varname Built-in variables: • $# is the number of argument • $1, $2, … are the arguments • $$ is the process ID • $? is exit code of last command
  • 23. #!/bin/bash message_1="Hello" message_2="World" message="$message_1 $message_2” # concatenate echo $message # assign with output of command nusers=$(grep -v ^# /etc/passwd | wc -l | awk '{print $1}') echo "Number of users: $nusers" # do the math answer=$((6*7)) echo "The life, the universe, and everything: $answer"
  • 24. Branches • Simple branching with if then else fi • Enclose condition with [] • elif is possible, too • Use case in esac when you can many cases and single condition String operators: -z is empty? -d is directory? -f is file? == equal to != not equal to Integer operators: -eq equal to -lt less than -ne not equal to -gt greater than
  • 25. branches.sh #!/bin/bash if [ -z "$1" ]; then name="Arthur" else name="$1" fi if [ "$name" != "Arthur" ]; then echo "Not Arthur" else echo "Hello Arthur" fi answer=$((6*7)) if [ $answer -eq 42 ]; then echo "Life, the universe, and everything" fi
  • 26. branches.sh - con’t case "$name" in "Arthur") echo "Welcome onboard" ;; "Trillian") echo "You know Arthur" ;; *) echo "Who are you?" ;; esac
  • 27. Loops • Simple loops: for … in … ; do … done • The seq utility can generate list of numbers • Conditional loops: while … ; do … done • Line-by-line: while read line ; do … done One-liner (similar to watch) while [ true ]; do clear; echo $RANDOM; sleep 1; done
  • 28. loops.sh#!/bin/bash # Multiplication table for i in $(seq 1 10); do echo "$i $((3*$i))" done # All .sh files for f in $(ls *.sh); do echo "$f $(head -1 $f | cut -c3-) $(wc -l $f | awk '{print $1}')" done # read self line-by-line i=1 cat $0 | while read line ; do nchars=$(echo "$line" | wc -c | awk '{print $1}') echo "$i $nchars" i=$(($i+1)) done | sort -n -k 2
  • 29. Functions • Functions can increase readability of your scripts • arguments are $1, $2, … • local variables can be used • return an integer and get it as $? • Use global variable to return a string 😒
  • 30. function.sh #!/bin/bash mult () { local n=$1 return $((3*$n)) } for n in $(seq 1 10); do mult $n echo "$n $?” done
  • 31. Tips and tricks • Use set -e to exit early • or use || exit 1 • set -O pipefail and you can get the exit code of the first failing program in a pipe • xcpretty never fails but xcodebuild might • Use tee to write to stdout and file • To trace (debugging): set -x or sh -x
  • 32. Tips and tricks • Always use “$var” when dealing with file names (and strings) • str=“fish horse”; for i in $str; do echo $i; done • str=“fish horse”; for i in “$str”; do echo $i; done • Call mkdir -p when creating folders • Create temp. files with mktemp /tmp/$$.XXXXXX • Using variable to modify behaviour of script: • FLAGS=“-O3 -libc++=stdlibc++” build.sh • Subshells: (cd foo && rm -f bar)
  • 34. Home brew • Home brew provides calories for console cowboys • You don’t have to be root to install • Software is installed in /usr/ local/Cellar, and symlinked to / usr/local/bin • Brew cask is for binary distribution • http://brew.sh and http:// caskroom.io Greg Peverill-Conti, https://www.flickr.com/photos/gregpc/ Examples: brew search bash brew info bash brew install bash brew update
  • 35. Tools for developers • Apple provides some basic tools • nm - display symbol table • c++filt - Prettify C++ and Java names • otool -L - display which shared libraries are required • libtool - create libraries • lipo - manipulate fat/universal binaries zzpza, https://www.flickr.com/photos/zzpza/ Examples: nm book.o | c++filt otool -L RealmInspector
  • 36. git • Home brew packages: • git, git-extras • Symlink /usr/local/bin/git to / usr/bin • Bash completion works • commands, branches, etc. • Fancy prompt: PS1='u@h:w$(__git_ps1 " (%s)") $ ‘ git log --graph --simplify-by-decoration --pretty=format:'%d' --all Examples: git count -all git contrib "Kenneth Geisshirt"
  • 37. Xcode • You can build Xcode projects at the command-line xcodebuild -scheme OreDevPlain - configuration Release -sdk iphonesimulator • Targets: clean, build, test • You can add shell scripts to build phases
  • 38. xcpretty • The output of xcodebuild can be hard to read • xcpretty makes it prettier • Installation: • sudo gem install xcpretty • Usage: • xbuildcode … | xcpretty
  • 39. xctool • Yet another build helper • Installation: • brew install xctool • Usage: • xctool -scheme OredevPlain - configuration Release -sdk iphonesimulator build
  • 40. Further information • Classical Shell Scripting. R. Arnolds and N.H.F. Beebe. O’Reilly Media, 2005. • The sed FAQ: http://sed.sourceforge.net/ sedfaq.html • Advanced Bash-Scripting Guide: http:// www.tldp.org/LDP/abs/html/ http://realm .io W e are hiring