SlideShare a Scribd company logo
1 of 27
© 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?

More Related Content

What's hot (20)

Low-level Accesses
Low-level AccessesLow-level Accesses
Low-level Accesses
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
System Calls
System CallsSystem Calls
System Calls
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Kernel Programming
Kernel ProgrammingKernel Programming
Kernel Programming
 
File System Modules
File System ModulesFile System Modules
File System Modules
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Toolchain
ToolchainToolchain
Toolchain
 
Introduction to Linux Drivers
Introduction to Linux DriversIntroduction to Linux Drivers
Introduction to Linux Drivers
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
 
Kernel Timing Management
Kernel Timing ManagementKernel Timing Management
Kernel Timing Management
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
 
Linux DMA Engine
Linux DMA EngineLinux DMA Engine
Linux DMA Engine
 
Architecture Porting
Architecture PortingArchitecture Porting
Architecture Porting
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
File System Modules
File System ModulesFile System Modules
File System Modules
 
Processes
ProcessesProcesses
Processes
 

Viewers also liked (11)

Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Threads
ThreadsThreads
Threads
 
Timers
TimersTimers
Timers
 
Signals
SignalsSignals
Signals
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
References
ReferencesReferences
References
 
Interrupts
InterruptsInterrupts
Interrupts
 

Similar to Shell Scripting

Lamp ppt
Lamp pptLamp ppt
Lamp ppt
Reka
 

Similar to Shell Scripting (20)

Linux System
Linux SystemLinux System
Linux System
 
Linux Internals Part - 1
Linux Internals Part - 1Linux Internals Part - 1
Linux Internals Part - 1
 
60761 linux
60761 linux60761 linux
60761 linux
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Basics of Linux Commands, Git and Github
Basics of Linux Commands, Git and GithubBasics of Linux Commands, Git and Github
Basics of Linux Commands, Git and Github
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Operating system (remuel)
Operating system (remuel)Operating system (remuel)
Operating system (remuel)
 
Shell scripting - By Vu Duy Tu from eXo Platform SEA
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
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpoint
 
unix.ppt
unix.pptunix.ppt
unix.ppt
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.ppt
 
Lamp ppt
Lamp pptLamp ppt
Lamp ppt
 
File Systems
File SystemsFile Systems
File Systems
 
Terminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partI
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
101 apend. scripting, crond, atd
101 apend. scripting, crond, atd101 apend. scripting, crond, atd
101 apend. scripting, crond, atd
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
Lamp ppt
Lamp pptLamp ppt
Lamp ppt
 

More from Anil Kumar Pugalia (10)

Processes
ProcessesProcesses
Processes
 
System Calls
System CallsSystem Calls
System Calls
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
 
Power of vi
Power of viPower of vi
Power of vi
 
"make" system
"make" system"make" system
"make" system
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Linux File System
Linux File SystemLinux File System
Linux File System
 

Recently uploaded

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 

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?