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 (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

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

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?