SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
Coming Out of Your Shell
Kel Cecil
@praisechaos
bash
Created by Brian Fox in
1989
Stallman was not pleased
with
for an open shell
another developer's
progress
zsh
Created by Paul Falstad in
1990 while a student at
Princeton.
Named after for Yale
professor Zhong Shao
whose login id was "zsh"
Shared history
(like FTP and TCP support)
Extended file globbing
Theme-able prompts
Sweet loadable modules
zsh configured with oh-my-zsh and demonstrating extended globbing
(Some) zsh Features
fish
Orignally written by Axel
Liljencrantz and released in
2005
"friendly interactive shell"
Considered an "exotic"
shell
Does not derive syntax
from Bourne or c shells
fish's design is opinionated
(Some) fish Features
Selectable, searchable tab-completion menu with helpful
descriptions
Web configuration tool (fish_config)
Aesthetic feedback on completions and more
Shell completions by parsing man pages
Event handlers
Digging a Little Deeper
Globbing
Referencing Files with Ease
What is Globbing?
The ability to get a list of filenames
matching some descriptive string
Proficiency with globbing can save a lot of
time.
Recursive Wildcards
Works out of the box in zsh, fish
Recursive Wildcards
bash 4.x
Opt-in Features for bash
There are several opt-in features for bash.
Opt-in is intended to preserve default behavior
where desired.
A list of opt-in features is available on the
.
Be sure to check it out if you're a bash person.
shopt
builtin info page
zsh's Glob Qualifiers
What if I'd like to find an .iso in my Downloads folder?
Filter down to images that are larger than 1 GB
Modified less than 1 Month Ago
*.iso(.Lg+1mM-1)
zsh's estrings
estrings allow you to use a comparison as a condition
for expansion
~/code/*(/e:'[[ -e ${REPLY}/.git ]]':)
zsh's glob qualifier abuse
Glob qualifiers can be nasty if abused.
~/code/*(-FUGmM+3e:'[[ -e ${REPLY}/.git ]]':^mM+12)
zsh's glob qualifier abuse
~/code/*(-FUGe:'[[ -e ${REPLY}/.git ]]':^mM+12)
Non-empty directories (F) in the code directory in my
home directory that are not symlinks (-)
Directories are owned by the current user (U) AND the
current user's primary group (G).
Include the directory if it includes a .git directory
(estring).
Do not include ( ^ ) directories modified more than 12
months ago.
There's plenty more...
Be sure to check out zsh's Expansion manual page
Scripting
Making the shell work for you
A simple example script
Takes a list of files and two words
Loops through each of the files
Ensure the file is a regular file
Replace the first word with the second word
Output a status line
Example:
./chtext.sh bruceBanner incredibleHulk ./data/*.txt
#!/bin/bash
# chtext - change text within multiple files
if [ $# -lt 3 ]; then
echo >&2 "usage: chtext old new [file ...]"
exit 1
fi
OLD="$1"
NEW="$2"
shift 2
for FILE
do
echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}"
if [ -r "${FILE}" ]
then
if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$
then
mv /tmp/ct$$ "${FILE}"
else
echo >&2 "chtext: could not change file: ${FILE}"
fi
fi
done
bash
#!/bin/bash
# chtext - change text within multiple files
if [ $# -lt 3 ]; then
echo >&2 "usage: chtext old new [file ...]"
exit 1
fi
OLD="$1"
NEW="$2"
shift 2
for FILE
do
echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}"
if [ -r "${FILE}" ]
then
if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$
then
mv /tmp/ct$$ "${FILE}"
else
echo >&2 "chtext: could not change file: ${FILE}"
fi
fi
done
bash
Check if we've supplied
fewer than three
parameters.
Exit with an error code
of 1 if so.
#!/bin/bash
# chtext - change text within multiple files
if [ $# -lt 3 ]; then
echo >&2 "usage: chtext old new [file ...]"
exit 1
fi
OLD="$1"
NEW="$2"
shift 2
for FILE
do
echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}"
if [ -r "${FILE}" ]
then
if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$
then
mv /tmp/ct$$ "${FILE}"
else
echo >&2 "chtext: could not change file: ${FILE}"
fi
fi
done
bash
Set our word to be
replaced as OLD and
the replacement word
as NEW
Shift the script
arguments two places.
Move all array
contents left two
places.
This removes the
first two array items.
#!/bin/bash
# chtext - change text within multiple files
if [ $# -lt 3 ]; then
echo >&2 "usage: chtext old new [file ...]"
exit 1
fi
OLD="$1"
NEW="$2"
shift 2
for FILE
do
echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}"
if [ -r "${FILE}" ]
then
if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$
then
mv /tmp/ct$$ "${FILE}"
else
echo >&2 "chtext: could not change file: ${FILE}"
fi
fi
done
bash
Loop through the
remaining script
arguments.
Set each argument to
the FILE variable.
This isn't exactly
intuitive...
#!/bin/bash
# chtext - change text within multiple files
if [ $# -lt 3 ]; then
echo >&2 "usage: chtext old new [file ...]"
exit 1
fi
OLD="$1"
NEW="$2"
shift 2
for FILE
do
echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}"
if [ -r "${FILE}" ]
then
if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$
then
mv /tmp/ct$$ "${FILE}"
else
echo >&2 "chtext: could not change file: ${FILE}"
fi
fi
done
bash
Check if the file is a
regular file.
Perform a sed to
replace the OLD word
with the new word and
write to a temp file.
$$ represents the
process ID for the
script.
If the sed returns a zero
status code, then
replace the file.
fish is a little different...
bash strives to be POSIX compliant
zsh strives to be compatible with bash
fish does it's own thing
fish is not POSIX compliant and considers that to
be a feature.
The scripting language is intended to be more
simple.
#!/usr/bin/env fish
# chtext - change text within multiple files
set VALUES (count $argv)
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
#!/usr/bin/env fish
# chtext - change text within multiple files
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
Check to see if our
arguments are less
than 3.
Script arguments are
stored in $argv
We use the math
builtin for our
comparison
Redirect the math
output to /dev/null to
avoid printing our
answer on stdout
#!/usr/bin/env fish
# chtext - change text within multiple files
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
fish uses "set" for
variable assignment.
#!/usr/bin/env fish
# chtext - change text within multiple files
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
List ranges can be
specified using ".."
The last item in the
list can be identified
by using "-1"
#!/usr/bin/env fish
# chtext - change text within multiple files
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
Notice that variables
do not have curly
braces "{}"
Curly braces are
optional in bash.
fish requires you
not use them.
fish will be nice
about it.
#!/usr/bin/env fish
# chtext - change text within multiple files
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
fish defers to
programs when
possible instead of
reimplementing
features.
This call to test
checks to see if a file
is a regular file.
#!/usr/bin/env fish
# chtext - change text within multiple files
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
echo >&2 "chtext: change $FILE: $OLD to $NEW"
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
else
echo >&2 "chtext: could not change file: $FILE"
end
end
end
fish
%self substitutes the
process ID in fish.
Using $$ as you
would in bash
results in a helpful
error message.
if math (count $argv) "<3" > /dev/null
echo >&2 "usage: chtext old new [file ...]"
exit 1
end
set OLD $argv[1]
set NEW $argv[2]
for FILE in $argv[3..-1]
if test -f $FILE
if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self
mv /tmp/ct%self "$FILE"
end
end
end
if [ $# -lt 3 ]; then
echo >&2 "usage: chtext old new [file ...]"
exit 1
fi
OLD="$1"
NEW="$2"
shift 2
for FILE
do
if [ -r "${FILE}" ]
then
if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$
then
mv /tmp/ct$$ "${FILE}"
fi
fi
done
Which do you prefer?
Bash?
or fish?
Frameworks
Why use shell frameworks?
Carefully manicured shell scripts can be a lot of work.
Community maintained scripts can be higher quality.
oh my zsh! oh my fish! bash it
Take Your Pick!
What are my takeaways?
bash is capable of more than it's given
credit for.
zsh is great for people who like to tweak
and invest the time into unlocking it's full
potential.
fish is fantastic for useful features right out
of the box.
All three shells have frameworks to try.
We've hardly scratched the surface...
Thanks for Listening!
Twitter: @praisechaos
Web: http://kelcecil.com
Here's a Game Boy Advance running Unix 5!

Mais conteúdo relacionado

Mais procurados

Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
Raghu nath
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
Quỳnh Phan
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
kayalkarnan
 

Mais procurados (16)

Fun with processes - lightning talk
Fun with processes - lightning talkFun with processes - lightning talk
Fun with processes - lightning talk
 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
 
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
The Hidden Power of HTMLBars (or, Scope in Ember.js Templates)
 
Linux system admin
Linux system adminLinux system admin
Linux system admin
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMail
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell Script
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Shell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address Information
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
 
08 php-files
08 php-files08 php-files
08 php-files
 
Unit vii wp ppt
Unit vii wp pptUnit vii wp ppt
Unit vii wp ppt
 
Rc - The Plan 9 Shell
Rc - The Plan 9 ShellRc - The Plan 9 Shell
Rc - The Plan 9 Shell
 
extending-php
extending-phpextending-php
extending-php
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
 

Semelhante a Coming Out Of Your Shell - A Comparison of *Nix Shells

Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
Dr.Ravi
 
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
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
erbipulkumar
 

Semelhante a Coming Out Of Your Shell - A Comparison of *Nix Shells (20)

Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
Unix 1st sem lab programs a - VTU Karnataka
Unix 1st sem lab programs a - VTU KarnatakaUnix 1st sem lab programs a - VTU Karnataka
Unix 1st sem lab programs a - VTU Karnataka
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell programming
Shell programmingShell programming
Shell programming
 
Unit VI
Unit VI Unit VI
Unit VI
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
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
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
unix_commands.ppt
unix_commands.pptunix_commands.ppt
unix_commands.ppt
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands
 
Linux Commands.pptx
Linux Commands.pptxLinux Commands.pptx
Linux Commands.pptx
 

Último

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Último (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Coming Out Of Your Shell - A Comparison of *Nix Shells

  • 1. Coming Out of Your Shell Kel Cecil @praisechaos
  • 2. bash Created by Brian Fox in 1989 Stallman was not pleased with for an open shell another developer's progress
  • 3. zsh Created by Paul Falstad in 1990 while a student at Princeton. Named after for Yale professor Zhong Shao whose login id was "zsh"
  • 4. Shared history (like FTP and TCP support) Extended file globbing Theme-able prompts Sweet loadable modules zsh configured with oh-my-zsh and demonstrating extended globbing (Some) zsh Features
  • 5. fish Orignally written by Axel Liljencrantz and released in 2005 "friendly interactive shell" Considered an "exotic" shell Does not derive syntax from Bourne or c shells fish's design is opinionated
  • 6. (Some) fish Features Selectable, searchable tab-completion menu with helpful descriptions Web configuration tool (fish_config) Aesthetic feedback on completions and more Shell completions by parsing man pages Event handlers
  • 9. What is Globbing? The ability to get a list of filenames matching some descriptive string Proficiency with globbing can save a lot of time.
  • 10. Recursive Wildcards Works out of the box in zsh, fish
  • 12. Opt-in Features for bash There are several opt-in features for bash. Opt-in is intended to preserve default behavior where desired. A list of opt-in features is available on the . Be sure to check it out if you're a bash person. shopt builtin info page
  • 13. zsh's Glob Qualifiers What if I'd like to find an .iso in my Downloads folder? Filter down to images that are larger than 1 GB Modified less than 1 Month Ago *.iso(.Lg+1mM-1)
  • 14. zsh's estrings estrings allow you to use a comparison as a condition for expansion ~/code/*(/e:'[[ -e ${REPLY}/.git ]]':)
  • 15. zsh's glob qualifier abuse Glob qualifiers can be nasty if abused. ~/code/*(-FUGmM+3e:'[[ -e ${REPLY}/.git ]]':^mM+12)
  • 16.
  • 17. zsh's glob qualifier abuse ~/code/*(-FUGe:'[[ -e ${REPLY}/.git ]]':^mM+12) Non-empty directories (F) in the code directory in my home directory that are not symlinks (-) Directories are owned by the current user (U) AND the current user's primary group (G). Include the directory if it includes a .git directory (estring). Do not include ( ^ ) directories modified more than 12 months ago.
  • 18. There's plenty more... Be sure to check out zsh's Expansion manual page
  • 20. A simple example script Takes a list of files and two words Loops through each of the files Ensure the file is a regular file Replace the first word with the second word Output a status line Example: ./chtext.sh bruceBanner incredibleHulk ./data/*.txt
  • 21. #!/bin/bash # chtext - change text within multiple files if [ $# -lt 3 ]; then echo >&2 "usage: chtext old new [file ...]" exit 1 fi OLD="$1" NEW="$2" shift 2 for FILE do echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}" if [ -r "${FILE}" ] then if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$ then mv /tmp/ct$$ "${FILE}" else echo >&2 "chtext: could not change file: ${FILE}" fi fi done bash
  • 22. #!/bin/bash # chtext - change text within multiple files if [ $# -lt 3 ]; then echo >&2 "usage: chtext old new [file ...]" exit 1 fi OLD="$1" NEW="$2" shift 2 for FILE do echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}" if [ -r "${FILE}" ] then if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$ then mv /tmp/ct$$ "${FILE}" else echo >&2 "chtext: could not change file: ${FILE}" fi fi done bash Check if we've supplied fewer than three parameters. Exit with an error code of 1 if so.
  • 23. #!/bin/bash # chtext - change text within multiple files if [ $# -lt 3 ]; then echo >&2 "usage: chtext old new [file ...]" exit 1 fi OLD="$1" NEW="$2" shift 2 for FILE do echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}" if [ -r "${FILE}" ] then if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$ then mv /tmp/ct$$ "${FILE}" else echo >&2 "chtext: could not change file: ${FILE}" fi fi done bash Set our word to be replaced as OLD and the replacement word as NEW Shift the script arguments two places. Move all array contents left two places. This removes the first two array items.
  • 24. #!/bin/bash # chtext - change text within multiple files if [ $# -lt 3 ]; then echo >&2 "usage: chtext old new [file ...]" exit 1 fi OLD="$1" NEW="$2" shift 2 for FILE do echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}" if [ -r "${FILE}" ] then if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$ then mv /tmp/ct$$ "${FILE}" else echo >&2 "chtext: could not change file: ${FILE}" fi fi done bash Loop through the remaining script arguments. Set each argument to the FILE variable. This isn't exactly intuitive...
  • 25. #!/bin/bash # chtext - change text within multiple files if [ $# -lt 3 ]; then echo >&2 "usage: chtext old new [file ...]" exit 1 fi OLD="$1" NEW="$2" shift 2 for FILE do echo >&2 "chtext: change ${FILE}: ${OLD} to ${NEW}" if [ -r "${FILE}" ] then if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$ then mv /tmp/ct$$ "${FILE}" else echo >&2 "chtext: could not change file: ${FILE}" fi fi done bash Check if the file is a regular file. Perform a sed to replace the OLD word with the new word and write to a temp file. $$ represents the process ID for the script. If the sed returns a zero status code, then replace the file.
  • 26. fish is a little different... bash strives to be POSIX compliant zsh strives to be compatible with bash fish does it's own thing fish is not POSIX compliant and considers that to be a feature. The scripting language is intended to be more simple.
  • 27. #!/usr/bin/env fish # chtext - change text within multiple files set VALUES (count $argv) if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish
  • 28. #!/usr/bin/env fish # chtext - change text within multiple files if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish Check to see if our arguments are less than 3. Script arguments are stored in $argv We use the math builtin for our comparison Redirect the math output to /dev/null to avoid printing our answer on stdout
  • 29. #!/usr/bin/env fish # chtext - change text within multiple files if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish fish uses "set" for variable assignment.
  • 30. #!/usr/bin/env fish # chtext - change text within multiple files if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish List ranges can be specified using ".." The last item in the list can be identified by using "-1"
  • 31. #!/usr/bin/env fish # chtext - change text within multiple files if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish Notice that variables do not have curly braces "{}" Curly braces are optional in bash. fish requires you not use them. fish will be nice about it.
  • 32. #!/usr/bin/env fish # chtext - change text within multiple files if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish fish defers to programs when possible instead of reimplementing features. This call to test checks to see if a file is a regular file.
  • 33. #!/usr/bin/env fish # chtext - change text within multiple files if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] echo >&2 "chtext: change $FILE: $OLD to $NEW" if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" else echo >&2 "chtext: could not change file: $FILE" end end end fish %self substitutes the process ID in fish. Using $$ as you would in bash results in a helpful error message.
  • 34. if math (count $argv) "<3" > /dev/null echo >&2 "usage: chtext old new [file ...]" exit 1 end set OLD $argv[1] set NEW $argv[2] for FILE in $argv[3..-1] if test -f $FILE if sed "s|$OLD|$NEW|g" < "$FILE" > /tmp/ct%self mv /tmp/ct%self "$FILE" end end end if [ $# -lt 3 ]; then echo >&2 "usage: chtext old new [file ...]" exit 1 fi OLD="$1" NEW="$2" shift 2 for FILE do if [ -r "${FILE}" ] then if sed "s|${OLD}|${NEW}|g" < "${FILE}" > /tmp/ct$$ then mv /tmp/ct$$ "${FILE}" fi fi done Which do you prefer? Bash? or fish?
  • 36. Why use shell frameworks? Carefully manicured shell scripts can be a lot of work. Community maintained scripts can be higher quality.
  • 37. oh my zsh! oh my fish! bash it Take Your Pick!
  • 38. What are my takeaways? bash is capable of more than it's given credit for. zsh is great for people who like to tweak and invest the time into unlocking it's full potential. fish is fantastic for useful features right out of the box. All three shells have frameworks to try. We've hardly scratched the surface...
  • 39. Thanks for Listening! Twitter: @praisechaos Web: http://kelcecil.com Here's a Game Boy Advance running Unix 5!