SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
The Bash Love
Ish Sookun
Executive Member, Linux User Group of Mauritius
Member, Mauritius Software Craftsmanship Community
ishwon@openSUSE.org
Ish Sookun The Bash Love
May 2014 @ University of Mauritius
Ish Sookun The Bash Love
First things first
A shell is a program that provides an
interface to the operating system,
which itself is an interface to the underlying
hardware (^^,) ...
A shell script is ridiculously just a bunch of
commands. One may use arguments and variables
coupled with logic control & a little bit of
arithmetic to �gure out what and when to run.
Popular shells are Bourne Shell
(sh), Bourne Again Shell (bash),
C Shell (csh), Korn Shell (ksh) ...
You may Google the rest and
have a moment of Shell history!
Ish Sookun The Bash Love
When to use Bash?
Run a series of external commands
Pipeline the output of one command as input to another
Code something with only simple logic
Develop incrementally
Create tools to extend your command-line environment
Ish Sookun The Bash Love
Know your Coreutils
Coreutils is a bunch of basic programs that run on Unix-like operating
systems, doing file, shell and text manipulation.
Most of these programs...
do one thing & do it well
work together
handle text streams
Ish Sookun The Bash Love
Files & directories
Everything
Links
Directories
cp
mv
rm
Copy files
Move/rename files
Delete files
ln Make links
mkdir
rmdir
Make directories
Remove directories
Ish Sookun The Bash Love
Text
Rows
cat
head
tail
sort
uniq
All rows
First rows
Last rows
Sort rows
Unique rows
Fields
cut
paste
join
Subset fields
Union fields
(rows in order)
Union fields
(rows joined by a field)
Ish Sookun The Bash Love
Pipes & redirects
Bash uses three standard I/O streams, each of which is associated with a
well-known file descriptor:
stdin having file descriptor 0
stdout having file descriptor 1
stderr having file descriptor 2
Examples:
ps -ef | grep -i httpd
ls -lRth > DirectoryContent.log
mysql -u admin -p awesomeDB < awesomeDB_Backup.sql
./myScript.sh 2> error.log
Ish Sookun The Bash Love
Let's begin with Shebang
Shebang, yes, that's how your Bash script starts. Oh! You don't write
shebang but write #! instead. Read more about Shebang on Google. (^^,)
#!/bin/bash
# This is an innocent comment
ME=`whoami`
echo "You've gone nuts, $ME."
chmod u+x myScript.sh
By convention give your Bash scripts a .sh extension.
You need to give execution right to your script before you're able to run it.
Now, execute it at the terminal prompt as follows:
./myScript.sh

Contenu connexe

Tendances

Unix Commands
Unix CommandsUnix Commands
Unix Commands
Dr.Ravi
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
Mustafa Qasim
 
Bash shell
Bash shellBash shell
Bash shell
xylas121
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
Rahul Pola
 

Tendances (20)

Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Unix Commands
Unix CommandsUnix Commands
Unix Commands
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Arcshell SSH Module Overview
Arcshell SSH Module  OverviewArcshell SSH Module  Overview
Arcshell SSH Module Overview
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Bash shell
Bash shellBash shell
Bash shell
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
16952 commands on shells
16952 commands on shells16952 commands on shells
16952 commands on shells
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Wildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell VariablesWildcards, Simple Shell Programs and Shell Variables
Wildcards, Simple Shell Programs and Shell Variables
 
Common linux ubuntu commands overview
Common linux  ubuntu commands overviewCommon linux  ubuntu commands overview
Common linux ubuntu commands overview
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 

Similaire à The Bash Love

Using Unix
Using UnixUsing Unix
Using Unix
Dr.Ravi
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
student
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
Norberto Angulo
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docx
SUBHI7
 

Similaire à The Bash Love (20)

Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptx
 
Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
Shell & Shell Script
Shell & Shell ScriptShell & Shell Script
Shell & Shell Script
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptx
 
Linux Bash.pdf
Linux Bash.pdfLinux Bash.pdf
Linux Bash.pdf
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.ppt
 
Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Unixscripting
UnixscriptingUnixscripting
Unixscripting
 
The Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docxThe Korn Shell is the UNIX shell (command execution program, often c.docx
The Korn Shell is the UNIX shell (command execution program, often c.docx
 
Licão 02 shell basics bash intro
Licão 02 shell basics bash introLicão 02 shell basics bash intro
Licão 02 shell basics bash intro
 
Ch03
Ch03Ch03
Ch03
 
Unix tutorial-08
Unix tutorial-08Unix tutorial-08
Unix tutorial-08
 

Plus de ishwon (6)

Logo Design Process by Nirvan
Logo Design Process by NirvanLogo Design Process by Nirvan
Logo Design Process by Nirvan
 
Running Tor on Android
Running Tor on AndroidRunning Tor on Android
Running Tor on Android
 
Entrepreneurship Prez by Santosh Achari
Entrepreneurship Prez by Santosh AchariEntrepreneurship Prez by Santosh Achari
Entrepreneurship Prez by Santosh Achari
 
MariaDB Prez by Joffrey Michaie
MariaDB Prez by Joffrey MichaieMariaDB Prez by Joffrey Michaie
MariaDB Prez by Joffrey Michaie
 
openSUSE Project Presentation during Linuxfest 2013
openSUSE Project Presentation during Linuxfest 2013openSUSE Project Presentation during Linuxfest 2013
openSUSE Project Presentation during Linuxfest 2013
 
openSUSE Project Presentation
openSUSE Project PresentationopenSUSE Project Presentation
openSUSE Project Presentation
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

The Bash Love

  • 1. The Bash Love Ish Sookun Executive Member, Linux User Group of Mauritius Member, Mauritius Software Craftsmanship Community ishwon@openSUSE.org Ish Sookun The Bash Love May 2014 @ University of Mauritius
  • 2. Ish Sookun The Bash Love First things first A shell is a program that provides an interface to the operating system, which itself is an interface to the underlying hardware (^^,) ... A shell script is ridiculously just a bunch of commands. One may use arguments and variables coupled with logic control & a little bit of arithmetic to �gure out what and when to run. Popular shells are Bourne Shell (sh), Bourne Again Shell (bash), C Shell (csh), Korn Shell (ksh) ... You may Google the rest and have a moment of Shell history!
  • 3. Ish Sookun The Bash Love When to use Bash? Run a series of external commands Pipeline the output of one command as input to another Code something with only simple logic Develop incrementally Create tools to extend your command-line environment
  • 4. Ish Sookun The Bash Love Know your Coreutils Coreutils is a bunch of basic programs that run on Unix-like operating systems, doing file, shell and text manipulation. Most of these programs... do one thing & do it well work together handle text streams
  • 5. Ish Sookun The Bash Love Files & directories Everything Links Directories cp mv rm Copy files Move/rename files Delete files ln Make links mkdir rmdir Make directories Remove directories
  • 6. Ish Sookun The Bash Love Text Rows cat head tail sort uniq All rows First rows Last rows Sort rows Unique rows Fields cut paste join Subset fields Union fields (rows in order) Union fields (rows joined by a field)
  • 7. Ish Sookun The Bash Love Pipes & redirects Bash uses three standard I/O streams, each of which is associated with a well-known file descriptor: stdin having file descriptor 0 stdout having file descriptor 1 stderr having file descriptor 2 Examples: ps -ef | grep -i httpd ls -lRth > DirectoryContent.log mysql -u admin -p awesomeDB < awesomeDB_Backup.sql ./myScript.sh 2> error.log
  • 8. Ish Sookun The Bash Love Let's begin with Shebang Shebang, yes, that's how your Bash script starts. Oh! You don't write shebang but write #! instead. Read more about Shebang on Google. (^^,) #!/bin/bash # This is an innocent comment ME=`whoami` echo "You've gone nuts, $ME." chmod u+x myScript.sh By convention give your Bash scripts a .sh extension. You need to give execution right to your script before you're able to run it. Now, execute it at the terminal prompt as follows: ./myScript.sh