The Bash Love
Ish Sookun
Executive Member, Linux User Group of Mauritius
Member, Mauritius Software Craftsmanship Communit...
Ish Sookun The Bash Love
First things first
A shell is a program that provides an
interface to the operating system,
which ...
Ish Sookun The Bash Love
When to use Bash?
Run a series of external commands
Pipeline the output of one command as input t...
Ish Sookun The Bash Love
Know your Coreutils
Coreutils is a bunch of basic programs that run on Unix-like operating
system...
Ish Sookun The Bash Love
Files & directories
Everything
Links
Directories
cp
mv
rm
Copy files
Move/rename files
Delete files
...
Ish Sookun The Bash Love
Text
Rows
cat
head
tail
sort
uniq
All rows
First rows
Last rows
Sort rows
Unique rows
Fields
cut
...
Ish Sookun The Bash Love
Pipes & redirects
Bash uses three standard I/O streams, each of which is associated with a
well-k...
Ish Sookun The Bash Love
Let's begin with Shebang
Shebang, yes, that's how your Bash script starts. Oh! You don't write
sh...
Upcoming SlideShare
Loading in …5
×

The Bash Love

1,225 views

Published on

Presentation about Bash Scripting during MSCC (Mauritius Software Craftsmanship Community) meetup at University of Mauritiuds. 3 May 2014.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,225
On SlideShare
0
From Embeds
0
Number of Embeds
787
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The Bash Love

  1. 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. 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. 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. 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. 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. 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. 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. 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

×