SlideShare a Scribd company logo
1 of 24
Team
Md. Iftiar Uddin Ahmed [011 122 084 ]
Md.Tanvir Hossain [ 011 101 035]
Rafid asrar prottoy [ 011 132 124 ]
Amit ghosh [011 132 134]
About Shell | Shell Scripts
Overview
 A short history of Linux
 About Shell
 About Shell Script
Linux
Introduction
 In 80’s, Microsoft’s DOS was the dominated OS for PC
 Apple MAC was better, but expensive
 UNIX was much better, but much, much more
expensive. Only for minicomputer for commercial
applications
 People was looking for a UNIX based system, which is
cheaper and can run on PC
 Both DOS, MAC and UNIX were proprietary, i.e., the
source code of their kernel is protected
 No modification is possible without paying high license
fees
Before
Linux
Beginning of
Linux
 A famous professor Andrew Tanenbaum developed Minix,
a simplified version of UNIX that runs on PC
 Minix is for class teaching only. No intention for
commercial use
 In Sept 1991, Linus Torvalds, a second year student of
Computer Science at the University of Helsinki,
developed the preliminary kernel of Linux, known as
Linux version 0.0.1
Linux
Introduction
Linux
Introduction
 Linux has been used for many computing platforms
– PC, PDA, Supercomputer,…
 Not only character user interface but graphical user interface is
available
 Commercial vendors moved in Linux itself to provide freely
distributed code. They make their money by compiling up
various software and gathering them in a distributable format
– Red Hat, Slackware, etc
Linux
Today
Shell
Shell is an command language interpreter that executes
commands read from the standard input device (keyboard) or from a
file. Shell is not part of system kernel, but uses the system kernel to
execute programs, create files etc.
Simply put, the shell is a program that takes your commands from
the keyboard and gives them to the operating system to perform.
What is Shell
Shell
Commands
 Shell commands are interpreted directly by the
shell you specify.
 The commands are similar to the statement in
some programming languages, such as C.
 Popular shells include:
 Enhanced C-shell tchs (csh+)
 Bourne-Again Shell, bash (sh+)
 Korn Shell (ksh)
Shells’
Features
 In particular:
 Pass arguments to your script
 Set and reference variables
 Use of control flow
 Interact with the user (read user input)
 Comments…
 Info on commands a given shell offers can be found
in the man pages for that shell.
 There are many Linux/UNIX references that give
detailed information and tips.
Shell Scripts
 To automate certain common activities an user
performs routinely.
 They serve the same purpose as batch files in
DOS/Windows.
 Example:
 rename 1000 files from upper case to
lowercase
What are they for?
What are Shell
Scripts
 Just text/ASCII files with:
 a set of standard UNIX/Linux commands (ls,
mv, cp, less, cat, etc.) along with
 flow of control
 some conditional logic and branching
(if-then),
 loop structures (foreach, for, while), and
 I/O facilities (echo, print, set, ...).
 They allow use of variables.
 They are interpreted by a shell directly.
 Some of them (csh, tcsh) share some of C
syntax.
 DOS/Win equivalent - batch files (.bat)
Why not use
C/C++ for
that?
 C/C++ programming requires compilation and
linkage, maybe libraries, which may not be
available (production servers).
 For the typical tasks much faster in development,
debugging, and maintenance (because they are
interpreted and do not require compilation).
Shell Script
Invocation
 Specify the shell directly:
 % tcsh myshellscript
 % tcsh -v myshellscript
(-v = verbose, useful for debugging)
 Make the shell an executable first and then run is a
command (set up an execution permission):
 % chmod u+x myshellscript
 Then either this:
 % myshellscript
(if the path variable has ‘.’ in it; security issue!)
 Or:
 % ./myshellscript
(should always work)
Shell Script
Invocation
continue
 If you get an error:
“myshellscrip: command not found”
 The probably “.” is not in your path or there’s no
execution bit set.
 When writing scripts, choose unique names, that
preferably do not match system commands.
 Bad name would be test for example, since there
are many shells with this internal command.
 To disambiguate, always precede the shell with “./” or
absolute path in case you have to name your thing not
very creatively.
Start Writing a
Shell Script
 The very first line, often called 'shebang' (#!) should
precede any other line, to assure that the right shell is
invoked.
 Comments start with '#', with the exception of #!, $#,
which are a special character sequences.
 Everything on a line after # is ignored if # is not a part
of a quoted string or a special character sequence.
#!/bin/tcsh #!/bin/bash
# This is for tcsh # For Bourne-Again Shell
#!/bin/sh
# This is for Bourne Shell
Variables
 Variables start with a $ sign when they are used.
 $x, $val
 There's no $ when a variable is declared.
 set x = 3
 @ y = 1
 set input = "$<"
 There are some system, predefined variables:
 $0, $1, $3 .... - argument references (arguments
themselves)
 $* - all the arguments
 $< - user's input from STDIN
 $# - # of arguments passed to the script
Read
 To read user input from keyboard and store it into a
 variable use read var1,var2,.....varn
#!/bin/bash
echo ‐n "Enter your name:”
read name
echo ‐n "Enter your student no:”
read stdno
echo "Your Name:$name”
echo "Your Age:$stdno”
Shell
Arithmetic
 The expr command evaluates its arguments as an
 expression.
 It is commonly used for simple arithmetic operations.
#!/bin/bash expr 1 + 1 expr 1 ‐ 1 expr 1 * 1 expr
1 / 1
va r=`expr 1 + 1`
x=1
x=`expr $x + 1`
Shell
Arithmetic
Continue
if
if ( <expression> ) then
<statements>
else if ( <another-expression> ) then
<statements>
else
<statements>
endif
foreach
foreach var ( <list-of-values> )
<statements>
end
Switch
switch ( string )
case str1:
<statements>
breaksw
...
default:
<statements>
breaksw
endsw
while
while ( <expression> )
<statements>
end
File Inquiry
Operators:
-op file
r Read access
w Write access
xExecute access
eExistence
oOwnership
z Zero size
s Non-zero size
F Plain file
D Directory
L Symbolic link
B Block special file
C Character special file
P Named pipe (FIFO)
S Socket special file

More Related Content

What's hot (20)

Shellscripting
ShellscriptingShellscripting
Shellscripting
 
Shell programming
Shell programmingShell programming
Shell programming
 
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
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
Unix shell scripting tutorial
Unix shell scripting tutorialUnix shell scripting tutorial
Unix shell scripting tutorial
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
 
Unix
UnixUnix
Unix
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Suman bhatt
Suman bhattSuman bhatt
Suman bhatt
 
Linux Shell Basics
Linux Shell BasicsLinux Shell Basics
Linux Shell Basics
 
Bash shell
Bash shellBash shell
Bash shell
 
Unix tutorial-08
Unix tutorial-08Unix tutorial-08
Unix tutorial-08
 
Unix shell scripts
Unix shell scriptsUnix shell scripts
Unix shell scripts
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUX
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 

Similar to Shell & Shell Script

Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Shell Scripting and Programming.pptx
Shell Scripting and Programming.pptxShell Scripting and Programming.pptx
Shell Scripting and Programming.pptxHarsha Patel
 
Using Unix
Using UnixUsing Unix
Using UnixDr.Ravi
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxkishore1986
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxrowiebornia
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptxDavidMaina47
 
Introduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkiiIntroduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkiicmdept1
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
Chapter 2 unix system commands
Chapter 2 unix system commandsChapter 2 unix system commands
Chapter 2 unix system commandsLukasJohnny
 
Unix Basics
Unix BasicsUnix Basics
Unix BasicsDr.Ravi
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02duquoi
 
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.docxSUBHI7
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linuxNorberto Angulo
 

Similar to Shell & Shell Script (20)

UnixShells.ppt
UnixShells.pptUnixShells.ppt
UnixShells.ppt
 
60761 linux
60761 linux60761 linux
60761 linux
 
Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02
 
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
 
Chap06
Chap06Chap06
Chap06
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Introduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkiiIntroduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkii
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Chapter 2 unix system commands
Chapter 2 unix system commandsChapter 2 unix system commands
Chapter 2 unix system commands
 
cisco
ciscocisco
cisco
 
3. intro
3. intro3. intro
3. intro
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 
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
 
Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
 

More from Amit Ghosh

Custom object detection using Deep Learning
Custom object detection using Deep Learning Custom object detection using Deep Learning
Custom object detection using Deep Learning Amit Ghosh
 
Data Set Analysis
Data Set Analysis Data Set Analysis
Data Set Analysis Amit Ghosh
 
Cloud platform comparison
Cloud platform comparison Cloud platform comparison
Cloud platform comparison Amit Ghosh
 
Gitlab runner in aws
Gitlab runner in aws Gitlab runner in aws
Gitlab runner in aws Amit Ghosh
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation Amit Ghosh
 
Restaurant ordering system
Restaurant ordering systemRestaurant ordering system
Restaurant ordering systemAmit Ghosh
 
System Analysis And Development Course
System Analysis And Development Course System Analysis And Development Course
System Analysis And Development Course Amit Ghosh
 
Convex hull presentation
Convex hull presentation Convex hull presentation
Convex hull presentation Amit Ghosh
 
Smart City Hackathon Presentation
Smart City Hackathon PresentationSmart City Hackathon Presentation
Smart City Hackathon PresentationAmit Ghosh
 
Pattern presentation
Pattern presentationPattern presentation
Pattern presentationAmit Ghosh
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)Amit Ghosh
 

More from Amit Ghosh (12)

Custom object detection using Deep Learning
Custom object detection using Deep Learning Custom object detection using Deep Learning
Custom object detection using Deep Learning
 
Data Set Analysis
Data Set Analysis Data Set Analysis
Data Set Analysis
 
Cloud platform comparison
Cloud platform comparison Cloud platform comparison
Cloud platform comparison
 
Gitlab runner in aws
Gitlab runner in aws Gitlab runner in aws
Gitlab runner in aws
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
Restaurant ordering system
Restaurant ordering systemRestaurant ordering system
Restaurant ordering system
 
System Analysis And Development Course
System Analysis And Development Course System Analysis And Development Course
System Analysis And Development Course
 
Bumble bee
Bumble beeBumble bee
Bumble bee
 
Convex hull presentation
Convex hull presentation Convex hull presentation
Convex hull presentation
 
Smart City Hackathon Presentation
Smart City Hackathon PresentationSmart City Hackathon Presentation
Smart City Hackathon Presentation
 
Pattern presentation
Pattern presentationPattern presentation
Pattern presentation
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Shell & Shell Script

  • 1. Team Md. Iftiar Uddin Ahmed [011 122 084 ] Md.Tanvir Hossain [ 011 101 035] Rafid asrar prottoy [ 011 132 124 ] Amit ghosh [011 132 134]
  • 2. About Shell | Shell Scripts
  • 3. Overview  A short history of Linux  About Shell  About Shell Script
  • 4. Linux Introduction  In 80’s, Microsoft’s DOS was the dominated OS for PC  Apple MAC was better, but expensive  UNIX was much better, but much, much more expensive. Only for minicomputer for commercial applications  People was looking for a UNIX based system, which is cheaper and can run on PC  Both DOS, MAC and UNIX were proprietary, i.e., the source code of their kernel is protected  No modification is possible without paying high license fees Before Linux
  • 5. Beginning of Linux  A famous professor Andrew Tanenbaum developed Minix, a simplified version of UNIX that runs on PC  Minix is for class teaching only. No intention for commercial use  In Sept 1991, Linus Torvalds, a second year student of Computer Science at the University of Helsinki, developed the preliminary kernel of Linux, known as Linux version 0.0.1 Linux Introduction
  • 6. Linux Introduction  Linux has been used for many computing platforms – PC, PDA, Supercomputer,…  Not only character user interface but graphical user interface is available  Commercial vendors moved in Linux itself to provide freely distributed code. They make their money by compiling up various software and gathering them in a distributable format – Red Hat, Slackware, etc Linux Today
  • 7. Shell Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file. Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc. Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. What is Shell
  • 8. Shell Commands  Shell commands are interpreted directly by the shell you specify.  The commands are similar to the statement in some programming languages, such as C.  Popular shells include:  Enhanced C-shell tchs (csh+)  Bourne-Again Shell, bash (sh+)  Korn Shell (ksh)
  • 9. Shells’ Features  In particular:  Pass arguments to your script  Set and reference variables  Use of control flow  Interact with the user (read user input)  Comments…  Info on commands a given shell offers can be found in the man pages for that shell.  There are many Linux/UNIX references that give detailed information and tips.
  • 10. Shell Scripts  To automate certain common activities an user performs routinely.  They serve the same purpose as batch files in DOS/Windows.  Example:  rename 1000 files from upper case to lowercase What are they for?
  • 11. What are Shell Scripts  Just text/ASCII files with:  a set of standard UNIX/Linux commands (ls, mv, cp, less, cat, etc.) along with  flow of control  some conditional logic and branching (if-then),  loop structures (foreach, for, while), and  I/O facilities (echo, print, set, ...).  They allow use of variables.  They are interpreted by a shell directly.  Some of them (csh, tcsh) share some of C syntax.  DOS/Win equivalent - batch files (.bat)
  • 12. Why not use C/C++ for that?  C/C++ programming requires compilation and linkage, maybe libraries, which may not be available (production servers).  For the typical tasks much faster in development, debugging, and maintenance (because they are interpreted and do not require compilation).
  • 13. Shell Script Invocation  Specify the shell directly:  % tcsh myshellscript  % tcsh -v myshellscript (-v = verbose, useful for debugging)  Make the shell an executable first and then run is a command (set up an execution permission):  % chmod u+x myshellscript  Then either this:  % myshellscript (if the path variable has ‘.’ in it; security issue!)  Or:  % ./myshellscript (should always work)
  • 14. Shell Script Invocation continue  If you get an error: “myshellscrip: command not found”  The probably “.” is not in your path or there’s no execution bit set.  When writing scripts, choose unique names, that preferably do not match system commands.  Bad name would be test for example, since there are many shells with this internal command.  To disambiguate, always precede the shell with “./” or absolute path in case you have to name your thing not very creatively.
  • 15. Start Writing a Shell Script  The very first line, often called 'shebang' (#!) should precede any other line, to assure that the right shell is invoked.  Comments start with '#', with the exception of #!, $#, which are a special character sequences.  Everything on a line after # is ignored if # is not a part of a quoted string or a special character sequence. #!/bin/tcsh #!/bin/bash # This is for tcsh # For Bourne-Again Shell #!/bin/sh # This is for Bourne Shell
  • 16. Variables  Variables start with a $ sign when they are used.  $x, $val  There's no $ when a variable is declared.  set x = 3  @ y = 1  set input = "$<"  There are some system, predefined variables:  $0, $1, $3 .... - argument references (arguments themselves)  $* - all the arguments  $< - user's input from STDIN  $# - # of arguments passed to the script
  • 17. Read  To read user input from keyboard and store it into a  variable use read var1,var2,.....varn #!/bin/bash echo ‐n "Enter your name:” read name echo ‐n "Enter your student no:” read stdno echo "Your Name:$name” echo "Your Age:$stdno”
  • 18. Shell Arithmetic  The expr command evaluates its arguments as an  expression.  It is commonly used for simple arithmetic operations. #!/bin/bash expr 1 + 1 expr 1 ‐ 1 expr 1 * 1 expr 1 / 1 va r=`expr 1 + 1` x=1 x=`expr $x + 1`
  • 20. if if ( <expression> ) then <statements> else if ( <another-expression> ) then <statements> else <statements> endif
  • 21. foreach foreach var ( <list-of-values> ) <statements> end
  • 22. Switch switch ( string ) case str1: <statements> breaksw ... default: <statements> breaksw endsw
  • 23. while while ( <expression> ) <statements> end
  • 24. File Inquiry Operators: -op file r Read access w Write access xExecute access eExistence oOwnership z Zero size s Non-zero size F Plain file D Directory L Symbolic link B Block special file C Character special file P Named pipe (FIFO) S Socket special file

Editor's Notes

  1. This is Linus Torvalds birthday 