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.๏ฌ‚ickr.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.๏ฌ‚ickr.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 ๏ฌle: >
โ€ข stdin from ๏ฌle <
โ€ข append stdout to ๏ฌle: >>
โ€ข 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
Con๏ฌguration
โ€ข $HOME/.bash_profile and $HOME/.bashrc
are your personal con๏ฌguration
โ€ข alias - useful for often used options
โ€ข Setting prompt (PS1) and search path (PATH)
โ€ข Reload con๏ฌguration: source ~/.bash_profile
.bash_pro๏ฌle
# 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 ๏ฌle content (magic numbers)
โ€ข lsof - list open ๏ฌles
โ€ข ps (aux or -ef) and top - show processes
โ€ข Simple watch:
while true ; do clear ; command ; sleep
n ; done
OS X speci๏ฌc commands
โ€ข open file - Starts registered program and open ๏ฌle
โ€ข 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 ๏ฌles: find . -name โ€˜*.oโ€™ -delete
Patterns: grep -r list *
Cut ๏ฌeld: 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 ๏ฌles non-
interactively
โ€ข Option -E gives an editing (regular)
expression
โ€ข s/FISH/HORSE/g - substitute
โ€ข /FISH/d - delete lines
joinash, https://www.๏ฌ‚ickr.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 ๏ฌelds
(spaces are default)
Patterns:
BEGIN - before opening ๏ฌle
END - after closing ๏ฌle
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 ๏ฌle?
== 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
๏ฌrst failing program in a pipe
โ€ข xcpretty never fails but xcodebuild might
โ€ข Use tee to write to stdout and ๏ฌle
โ€ข To trace (debugging): set -x or sh -x
Tips and tricks
โ€ข Always use โ€œ$varโ€ when dealing with ๏ฌle 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. ๏ฌles 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.๏ฌ‚ickr.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.๏ฌ‚ickr.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 Hadoop
Sages
ย 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
Confiz
ย 
Pythonๅœจ่ฑ†็“ฃ็š„ๅบ”็”จ
Pythonๅœจ่ฑ†็“ฃ็š„ๅบ”็”จPythonๅœจ่ฑ†็“ฃ็š„ๅบ”็”จ
Pythonๅœจ่ฑ†็“ฃ็š„ๅบ”็”จ
Qiangning Hong
ย 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
Amos 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 Experience
Alexander Gladysh
ย 

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

Bash shell
Bash shellBash shell
Bash shell
xylas121
ย 
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
brian_dailey
ย 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Sudharsan S
ย 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
Abhay Sapru
ย 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
Dr.Ravi
ย 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cd
jacko91
ย 

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

Naturvidenskabsfestival 2012
Naturvidenskabsfestival 2012Naturvidenskabsfestival 2012
Naturvidenskabsfestival 2012
Kenneth Geisshirt
ย 
JavaScript/Emacs integration
JavaScript/Emacs integrationJavaScript/Emacs integration
JavaScript/Emacs integration
Kenneth 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

CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
bodapatigopi8531
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
anilsa9823
ย 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS LiveVip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
ย 

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.๏ฌ‚ickr.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.๏ฌ‚ickr.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 ๏ฌle: > โ€ข stdin from ๏ฌle < โ€ข append stdout to ๏ฌle: >> โ€ข 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. Con๏ฌguration โ€ข $HOME/.bash_profile and $HOME/.bashrc are your personal con๏ฌguration โ€ข alias - useful for often used options โ€ข Setting prompt (PS1) and search path (PATH) โ€ข Reload con๏ฌguration: source ~/.bash_profile
  • 10. .bash_pro๏ฌle # 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 ๏ฌle content (magic numbers) โ€ข lsof - list open ๏ฌles โ€ข ps (aux or -ef) and top - show processes โ€ข Simple watch: while true ; do clear ; command ; sleep n ; done
  • 15. OS X speci๏ฌc commands โ€ข open file - Starts registered program and open ๏ฌle โ€ข 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 ๏ฌles: find . -name โ€˜*.oโ€™ -delete Patterns: grep -r list * Cut ๏ฌeld: 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 ๏ฌles non- interactively โ€ข Option -E gives an editing (regular) expression โ€ข s/FISH/HORSE/g - substitute โ€ข /FISH/d - delete lines joinash, https://www.๏ฌ‚ickr.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 ๏ฌelds (spaces are default) Patterns: BEGIN - before opening ๏ฌle END - after closing ๏ฌle 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 ๏ฌle? == 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 ๏ฌrst failing program in a pipe โ€ข xcpretty never fails but xcodebuild might โ€ข Use tee to write to stdout and ๏ฌle โ€ข To trace (debugging): set -x or sh -x
  • 32. Tips and tricks โ€ข Always use โ€œ$varโ€ when dealing with ๏ฌle 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. ๏ฌles 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.๏ฌ‚ickr.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.๏ฌ‚ickr.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