Shell Scripting

Anil Kumar Pugalia
Anil Kumar PugaliaLinux Geek and Open Source Hardware & Software Freak, Corporate Trainer, Entrepreneur in Automation
© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Shell Scripting
2© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
W's of Shell Scripting
Shell Commands: Bash & Linux
Bash: The Language
Scripting: Programming the Shell
Regular Expressions
Automation & Testing
3© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
W's of Shell Scripting
What is a Shell?
Various types of Shells
Bourne Shell (sh)
C Shell (csh)
Korn Shell (ksh)
Bourne Again Shell (bash)
TENEX csh (tcsh)
Z Shell (zsh)
Busybox (busybox) – Embedded Systems
What is Scripting?
Various types of Scripting
Shell
Perl, Python, Tcl/Tk, ...
PHP, Javascript, ...
4© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Bourne Again SHell
env - shell environment variables
export [var_name] - export a shell variable
HOME - path to user’s home directory
PATH - executable search path
PWD - present user directory
PS1 - command prompt
which - shows executable path
history - command recall
5© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Bourne Again SHell ...
alias - create shortcuts to commands
file - shows the information about a file
type - shows information about a command
Setup Scripts
/etc/profile – System wide startup script
~/.bash_profile – User specific startup script
~/.bashrc – Shell specific startup script
~/.bash_logout – User specific shutdown script
6© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Usage & Commands
Root & System Directories
File Basics & related Commands
User Basics & related Commands
File Access Permissions
System & Help Information
Standard I/O, Redirection and Pipes
7© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
/
the Root of an inverted tree
The top-most or super-parent directory
The container of your computer
Type: ls /
8© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
System Directories
/bin, /sbin - system binaries/applications
/var - logs, mails
/proc, /sys - “virtual” windows into the kernel
/etc - configuration files
/lib - shared system libraries
/dev - device files
/boot - Linux kernel and boot related binary files
/opt - for third-party packages
/root, /home - home directory for super user & other users
/usr - user space related files and dirs (binaries, libraries, ...)
/tmp - scratch pad
/mnt - mount points
9© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
File Basics
Every thing is viewed as a file in Linux
A file under the /
Seven Types
Regular (-)
Directory (d)
Character Device (c)
Block Device (b)
Named Pipe (p)
Socket (s)
Symbolic Link (l)
10© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
File related Shell Commands
ls - list directory/file contents
cd - change directory
pwd - print working directory
df - disk free
du - disk usage
cp - copy
mv - move, rename
rm - remove
mkdir - make directory
rmdir - remove directory
cat, less, head, tail - used to
view text files
vi, vim - editors
touch - create and update
files
grep - search in files
find, locate - search for files
gzip, gunzip, bzip, bunzip -
compression
tar - archive
sed, awk - file manipulation
11© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
User Basics
All Accesses into a Linux System are through a
User with a Password
Super User - root
Normal Users - <user_name>
Files: /etc/passwd, /etc/shadow
Users can be categorized into groups
root, bin, sys, adm, …
File: /etc/group
12© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
User related Shell Commands
adduser - create user
deluser - delete user
moduser - modify user
su - <username> - start new shell as different
user
finger - user information lookup
passwd - change or create user password
who, w, users - to find out who is logged in
13© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
User & File Access
All Files have User specific ownerships & access
permissions
Type: ls -l
–rw–r––r––
Symbol Name Number Position
r read 4 r--
w write 2 -w-
x execute 1 --x
type user group other
user (anil) group (anil)
14© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Related Shell Commands
chmod – Change file permissions
chown – Change file owner
chgrp – Change file group
15© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Few “Help”ful Shell Commands
uname - print system information
man <topic> - manual pages
info <topic> - information pages
16© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Manuals
Divided into sections
1 Shell commands e.g. mv, ls, cat
2 System calls e.g. _exit, read, write
3 Library calls e.g. exit, printf
4 Device and network specific info e.g. mouse, ttyS, null
5 File formats e.g. passwd, termcap
6 Games and demos e.g. fortune, worms
7 Miscellaneous e.g. ascii, fifo, pthreads
8 Administrative commands e.g. fsck, network daemons
9 POSIX Programmer Manual
Info pages are also available
17© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Standard Input & Outputs
Standard Input – 0 (default: keyboard)
read
Standard Output – 1 (default: monitor)
echo
Standard Error – 2 (default: monitor)
q
18© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Redirections & Pipes
command < file - reads standard input from file
command > file - directs standard output to file
command >> file - appends standard output to file
command 2> file - directs standard error to file
command 2>> file - appends standard error to file
command > file 2>&1 - both std output & error to file
cmd1 | cmd2 - transfer o/p of cmd1 as i/p to cmd2
<<word – here document
<<<word – here string
<>word – open file reading & writing
19© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
bash: The Language
#!, Comments, Space Sensitivity
Command-line Arguments & shift
Return Values
Variables & their Values
Built-in: $#, $*, $1, $@, $?, $$, …
User-defined
Evaluation & Brackets - [], {}, ()
Quotes
20© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Scripting the Shell
Control Structures
if ... then … else … fi
while ... do … done
for ... in … do … done (Helper: seq)
case ... in … ) … ;; … esac
Operators
Comparison: String, Integers
Logical: True & False
Functions
21© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Regular Expressions
Atoms: Symbols, Ranges, Any
*, +, ?
Range repetition: {}
Negation: ^
Subexpressions: (...)
Back references: 1, 2, …
Words: <...>, ^, $
22© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
RE & File Processing
vi, sed
echo, cut
grep, find
awk
23© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Automation
Putting all these together
Mixing & Matching of various Languages
Based on Power of Expression
Based on Ease of Use
Examples
Interactivity: Expect
File Processing & RE: Perl
GUI: Tcl/Tk, Python
24© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Test Automation
Common Requirements
Batch Processing
Input Triggers
Output Logging
Output Processing
Output Analysis & Actions
Involves
Command Repetitions
Interactivity & User Interfaces
File Organization & Processing
Data Parsing, Sorting, Sieving, ...
25© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Powerful Commands to Note
Script Generation: vi
Redirections & Pipes
Processing: sort, uniq
RE: sed, cut, grep, find
Sub-language: awk
26© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
W's of Shell Scripting
Shell Commands: Bash & Linux
Bash: The Language
Scripting: Programming the Shell
Regular Expressions
Automation & Testing
27© 2010-14 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?
1 of 27

Recommended

Bootloaders by
BootloadersBootloaders
BootloadersAnil Kumar Pugalia
10K views19 slides
Introduction to Linux by
Introduction to LinuxIntroduction to Linux
Introduction to LinuxAnil Kumar Pugalia
4K views33 slides
gcc and friends by
gcc and friendsgcc and friends
gcc and friendsAnil Kumar Pugalia
14.3K views11 slides
BeagleBoard-xM Bootloaders by
BeagleBoard-xM BootloadersBeagleBoard-xM Bootloaders
BeagleBoard-xM BootloadersSysPlay eLearning Academy for You
7.3K views17 slides
Linux User Space Debugging & Profiling by
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingAnil Kumar Pugalia
6.5K views36 slides
Kernel Debugging & Profiling by
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & ProfilingAnil Kumar Pugalia
6K views14 slides

More Related Content

What's hot

Low-level Accesses by
Low-level AccessesLow-level Accesses
Low-level AccessesAnil Kumar Pugalia
25.3K views16 slides
Block Drivers by
Block DriversBlock Drivers
Block DriversAnil Kumar Pugalia
38.4K views21 slides
System Calls by
System CallsSystem Calls
System CallsAnil Kumar Pugalia
9.7K views14 slides
PCI Drivers by
PCI DriversPCI Drivers
PCI DriversAnil Kumar Pugalia
44.5K views16 slides
SPI Drivers by
SPI DriversSPI Drivers
SPI DriversSysPlay eLearning Academy for You
10.2K views20 slides
Kernel Programming by
Kernel ProgrammingKernel Programming
Kernel ProgrammingAnil Kumar Pugalia
24.5K views25 slides

What's hot(20)

Viewers also liked

Mobile Hacking using Linux Drivers by
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversAnil Kumar Pugalia
6K views33 slides
Embedded Software Design by
Embedded Software DesignEmbedded Software Design
Embedded Software DesignAnil Kumar Pugalia
7K views29 slides
Functional Programming with LISP by
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISPAnil Kumar Pugalia
6.1K views23 slides
Embedded C by
Embedded CEmbedded C
Embedded CAnil Kumar Pugalia
25.7K views20 slides
Threads by
ThreadsThreads
ThreadsAnil Kumar Pugalia
10.2K views39 slides
Timers by
TimersTimers
TimersAnil Kumar Pugalia
6.5K views7 slides

Similar to Shell Scripting

Linux System by
Linux SystemLinux System
Linux SystemSysPlay eLearning Academy for You
854 views25 slides
Linux Internals Part - 1 by
Linux Internals Part - 1Linux Internals Part - 1
Linux Internals Part - 1SysPlay eLearning Academy for You
93 views70 slides
60761 linux by
60761 linux60761 linux
60761 linuxRitika Ahlawat
247 views46 slides
Complete Guide for Linux shell programming by
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
1.2K views142 slides
Basics of Linux Commands, Git and Github by
Basics of Linux Commands, Git and GithubBasics of Linux Commands, Git and Github
Basics of Linux Commands, Git and GithubDevang Garach
153 views24 slides
Linux Commands by
Linux CommandsLinux Commands
Linux CommandsRamasubbu .P
3.8K views23 slides

Similar to Shell Scripting(20)

Complete Guide for Linux shell programming by sudhir singh yadav
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
sudhir singh yadav1.2K views
Basics of Linux Commands, Git and Github by Devang Garach
Basics of Linux Commands, Git and GithubBasics of Linux Commands, Git and Github
Basics of Linux Commands, Git and Github
Devang Garach153 views
Shell scripting - By Vu Duy Tu from eXo Platform SEA by Thuy_Dang
Shell scripting - By Vu Duy Tu from eXo Platform SEAShell scripting - By Vu Duy Tu from eXo Platform SEA
Shell scripting - By Vu Duy Tu from eXo Platform SEA
Thuy_Dang1.3K views
Linux powerpoint by bijanshr
Linux powerpointLinux powerpoint
Linux powerpoint
bijanshr1.8K views
Lamp ppt by Reka
Lamp pptLamp ppt
Lamp ppt
Reka1K views
Terminal basic-commands(Unix) -partI by Kedar Bhandari
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partI
Kedar Bhandari624 views
Useful Linux and Unix commands handbook by Wave Digitech
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
Wave Digitech11.7K views

More from Anil Kumar Pugalia

Processes by
ProcessesProcesses
ProcessesAnil Kumar Pugalia
7K views33 slides
System Calls by
System CallsSystem Calls
System CallsAnil Kumar Pugalia
4.2K views17 slides
Playing with R L C Circuits by
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C CircuitsAnil Kumar Pugalia
2.8K views17 slides
Audio Drivers by
Audio DriversAudio Drivers
Audio DriversAnil Kumar Pugalia
20.8K views11 slides
Power of vi by
Power of viPower of vi
Power of viAnil Kumar Pugalia
3K views9 slides
"make" system by
"make" system"make" system
"make" systemAnil Kumar Pugalia
4.2K views10 slides

Recently uploaded

Tunable Laser (1).pptx by
Tunable Laser (1).pptxTunable Laser (1).pptx
Tunable Laser (1).pptxHajira Mahmood
23 views37 slides
The details of description: Techniques, tips, and tangents on alternative tex... by
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
121 views24 slides
Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
17 views1 slide
DALI Basics Course 2023 by
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023Ivory Egg
14 views12 slides
Future of Learning - Yap Aye Wee.pdf by
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdfNUS-ISS
41 views11 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
209 views20 slides

Recently uploaded(20)

The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze by NUS-ISS
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
NUS-ISS19 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk88 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views

Shell Scripting

  • 1. © 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Shell Scripting
  • 2. 2© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? W's of Shell Scripting Shell Commands: Bash & Linux Bash: The Language Scripting: Programming the Shell Regular Expressions Automation & Testing
  • 3. 3© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. W's of Shell Scripting What is a Shell? Various types of Shells Bourne Shell (sh) C Shell (csh) Korn Shell (ksh) Bourne Again Shell (bash) TENEX csh (tcsh) Z Shell (zsh) Busybox (busybox) – Embedded Systems What is Scripting? Various types of Scripting Shell Perl, Python, Tcl/Tk, ... PHP, Javascript, ...
  • 4. 4© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Bourne Again SHell env - shell environment variables export [var_name] - export a shell variable HOME - path to user’s home directory PATH - executable search path PWD - present user directory PS1 - command prompt which - shows executable path history - command recall
  • 5. 5© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Bourne Again SHell ... alias - create shortcuts to commands file - shows the information about a file type - shows information about a command Setup Scripts /etc/profile – System wide startup script ~/.bash_profile – User specific startup script ~/.bashrc – Shell specific startup script ~/.bash_logout – User specific shutdown script
  • 6. 6© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux Usage & Commands Root & System Directories File Basics & related Commands User Basics & related Commands File Access Permissions System & Help Information Standard I/O, Redirection and Pipes
  • 7. 7© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. / the Root of an inverted tree The top-most or super-parent directory The container of your computer Type: ls /
  • 8. 8© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. System Directories /bin, /sbin - system binaries/applications /var - logs, mails /proc, /sys - “virtual” windows into the kernel /etc - configuration files /lib - shared system libraries /dev - device files /boot - Linux kernel and boot related binary files /opt - for third-party packages /root, /home - home directory for super user & other users /usr - user space related files and dirs (binaries, libraries, ...) /tmp - scratch pad /mnt - mount points
  • 9. 9© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. File Basics Every thing is viewed as a file in Linux A file under the / Seven Types Regular (-) Directory (d) Character Device (c) Block Device (b) Named Pipe (p) Socket (s) Symbolic Link (l)
  • 10. 10© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. File related Shell Commands ls - list directory/file contents cd - change directory pwd - print working directory df - disk free du - disk usage cp - copy mv - move, rename rm - remove mkdir - make directory rmdir - remove directory cat, less, head, tail - used to view text files vi, vim - editors touch - create and update files grep - search in files find, locate - search for files gzip, gunzip, bzip, bunzip - compression tar - archive sed, awk - file manipulation
  • 11. 11© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. User Basics All Accesses into a Linux System are through a User with a Password Super User - root Normal Users - <user_name> Files: /etc/passwd, /etc/shadow Users can be categorized into groups root, bin, sys, adm, … File: /etc/group
  • 12. 12© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. User related Shell Commands adduser - create user deluser - delete user moduser - modify user su - <username> - start new shell as different user finger - user information lookup passwd - change or create user password who, w, users - to find out who is logged in
  • 13. 13© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. User & File Access All Files have User specific ownerships & access permissions Type: ls -l –rw–r––r–– Symbol Name Number Position r read 4 r-- w write 2 -w- x execute 1 --x type user group other user (anil) group (anil)
  • 14. 14© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Related Shell Commands chmod – Change file permissions chown – Change file owner chgrp – Change file group
  • 15. 15© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Few “Help”ful Shell Commands uname - print system information man <topic> - manual pages info <topic> - information pages
  • 16. 16© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux Manuals Divided into sections 1 Shell commands e.g. mv, ls, cat 2 System calls e.g. _exit, read, write 3 Library calls e.g. exit, printf 4 Device and network specific info e.g. mouse, ttyS, null 5 File formats e.g. passwd, termcap 6 Games and demos e.g. fortune, worms 7 Miscellaneous e.g. ascii, fifo, pthreads 8 Administrative commands e.g. fsck, network daemons 9 POSIX Programmer Manual Info pages are also available
  • 17. 17© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Standard Input & Outputs Standard Input – 0 (default: keyboard) read Standard Output – 1 (default: monitor) echo Standard Error – 2 (default: monitor) q
  • 18. 18© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Redirections & Pipes command < file - reads standard input from file command > file - directs standard output to file command >> file - appends standard output to file command 2> file - directs standard error to file command 2>> file - appends standard error to file command > file 2>&1 - both std output & error to file cmd1 | cmd2 - transfer o/p of cmd1 as i/p to cmd2 <<word – here document <<<word – here string <>word – open file reading & writing
  • 19. 19© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. bash: The Language #!, Comments, Space Sensitivity Command-line Arguments & shift Return Values Variables & their Values Built-in: $#, $*, $1, $@, $?, $$, … User-defined Evaluation & Brackets - [], {}, () Quotes
  • 20. 20© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Scripting the Shell Control Structures if ... then … else … fi while ... do … done for ... in … do … done (Helper: seq) case ... in … ) … ;; … esac Operators Comparison: String, Integers Logical: True & False Functions
  • 21. 21© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Regular Expressions Atoms: Symbols, Ranges, Any *, +, ? Range repetition: {} Negation: ^ Subexpressions: (...) Back references: 1, 2, … Words: <...>, ^, $
  • 22. 22© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. RE & File Processing vi, sed echo, cut grep, find awk
  • 23. 23© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Automation Putting all these together Mixing & Matching of various Languages Based on Power of Expression Based on Ease of Use Examples Interactivity: Expect File Processing & RE: Perl GUI: Tcl/Tk, Python
  • 24. 24© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Test Automation Common Requirements Batch Processing Input Triggers Output Logging Output Processing Output Analysis & Actions Involves Command Repetitions Interactivity & User Interfaces File Organization & Processing Data Parsing, Sorting, Sieving, ...
  • 25. 25© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Powerful Commands to Note Script Generation: vi Redirections & Pipes Processing: sort, uniq RE: sed, cut, grep, find Sub-language: awk
  • 26. 26© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? W's of Shell Scripting Shell Commands: Bash & Linux Bash: The Language Scripting: Programming the Shell Regular Expressions Automation & Testing
  • 27. 27© 2010-14 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?