SlideShare a Scribd company logo
SHELL PROGRAMMING                             LOOPING
QUICK REFERENCE GUIDE                         FOR
                                                    for variable in file/list
                                                    do
SPECIAL CHARACTERS
                                                             command
;     command separator
                                                    done
()    execute commands in subshell
{}    execute commands in current shell
                                              WHILE/UNTIL
#     comments
                                                    while/until test/condition
$var  variable
                                                    do
&     execute in the background
                                                            command
`     substitute standard out
                                                    done
‘     quote all characters in a string
“     as ‘ but allow substitution
                                              CASE
                                                       case option in
REGULAR EXPRESSIONS
                                                                option1) command;;
.       match any single character
                                                                option2) command;;
$       match preceding regular expression
                 at the end of a line                           *) command;;
^       match preceding regular expression             esac
                 at the beginning of a line            (* is any non-defined option)
*       match zero or more occurrences of
                 preceding expression         IF
[]      match any character in the brackets            if test/condition then
                 (or range, i.e. 2-8)                            command
[^ ]    match any character not in brackets            elif test/expression then
                 (i.e., ^0-9 means non-                          command
                 numeric character)                    else
      last regular expression encountered                      command
(exp) remember expression for later                  fi
                 reference
{m,n} number of times occurring, with m     REPETITION
{m}            indicating minimum and n           xargs -n
{m,}           indicating maximum                 (see man page for more options)

COMMANDS
exit code                                     VARIABLE EXPANSION
Exit shell with code return code              ${var} simple variable substitution
                                              ${var:=value}
break level                                           assign default value if not defined
Escape from level of for or while loop        ${var:+value}
                                                      substitute value if var is non-null
continue level                                ${var:-value}
Continue from level of for or while loop              temporarily assign value if non-null
                                              ${var:?value}
read
                                                      issue error with value if var not set,
Read input from a file
                                                               otherwise substitute value
test
Evaluate an expression or condition

trap                                          Compiled by Michael Oliveri (www.mikeoliveri.com)
Used for error handling                       Feel free to print a copy for yourself!

More Related Content

PDF
Shell Scripting Structured Commands
PDF
Vi CheatSheet
PPT
Regular expressions in Perl
PPTX
Strings,patterns and regular expressions in perl
PPTX
Final project powerpoint template (fndprg) (1)
PPTX
Cold fusion best practice
PPTX
Subroutines in perl
PDF
Polarion Conf 2012 - Come Emerasoft ti veste Polarion
Shell Scripting Structured Commands
Vi CheatSheet
Regular expressions in Perl
Strings,patterns and regular expressions in perl
Final project powerpoint template (fndprg) (1)
Cold fusion best practice
Subroutines in perl
Polarion Conf 2012 - Come Emerasoft ti veste Polarion

Similar to Shell quick reference (20)

PPT
Talk Unix Shell Script 1
PPT
Talk Unix Shell Script
PPTX
Scripting ppt
PDF
Bash Cheat Sheet - SniferL4bs
PPTX
Scripting ppt
PPT
Perl Intro 4 Debugger
PPS
UNIX - Class3 - Programming Constructs
PPTX
Shell Programming Language in Operating System .pptx
PDF
perl-pocket
PDF
perl-pocket
PDF
perl-pocket
PDF
perl-pocket
DOCX
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
DOCX
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
PDF
429 e8d01
PDF
003 scripting
PPTX
shellScriptAlt.pptx
PPT
Perl Intro 3 Datalog Parsing
PDF
Lecture19-20
PDF
Lecture19-20
Talk Unix Shell Script 1
Talk Unix Shell Script
Scripting ppt
Bash Cheat Sheet - SniferL4bs
Scripting ppt
Perl Intro 4 Debugger
UNIX - Class3 - Programming Constructs
Shell Programming Language in Operating System .pptx
perl-pocket
perl-pocket
perl-pocket
perl-pocket
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
429 e8d01
003 scripting
shellScriptAlt.pptx
Perl Intro 3 Datalog Parsing
Lecture19-20
Lecture19-20
Ad

More from Alessandro Grandi (7)

PDF
SUSE Linux quick reference
PDF
Linux quick reference
PDF
Lvm cesvip
PDF
Cesvip 2010 first_linux_module
ODP
Cesvip 20110127
ODP
Cesvip 20110124
ODP
Cesvip 20110120
SUSE Linux quick reference
Linux quick reference
Lvm cesvip
Cesvip 2010 first_linux_module
Cesvip 20110127
Cesvip 20110124
Cesvip 20110120
Ad

Shell quick reference

  • 1. SHELL PROGRAMMING LOOPING QUICK REFERENCE GUIDE FOR for variable in file/list do SPECIAL CHARACTERS command ; command separator done () execute commands in subshell {} execute commands in current shell WHILE/UNTIL # comments while/until test/condition $var variable do & execute in the background command ` substitute standard out done ‘ quote all characters in a string “ as ‘ but allow substitution CASE case option in REGULAR EXPRESSIONS option1) command;; . match any single character option2) command;; $ match preceding regular expression at the end of a line *) command;; ^ match preceding regular expression esac at the beginning of a line (* is any non-defined option) * match zero or more occurrences of preceding expression IF [] match any character in the brackets if test/condition then (or range, i.e. 2-8) command [^ ] match any character not in brackets elif test/expression then (i.e., ^0-9 means non- command numeric character) else last regular expression encountered command (exp) remember expression for later fi reference {m,n} number of times occurring, with m REPETITION {m} indicating minimum and n xargs -n {m,} indicating maximum (see man page for more options) COMMANDS exit code VARIABLE EXPANSION Exit shell with code return code ${var} simple variable substitution ${var:=value} break level assign default value if not defined Escape from level of for or while loop ${var:+value} substitute value if var is non-null continue level ${var:-value} Continue from level of for or while loop temporarily assign value if non-null ${var:?value} read issue error with value if var not set, Read input from a file otherwise substitute value test Evaluate an expression or condition trap Compiled by Michael Oliveri (www.mikeoliveri.com) Used for error handling Feel free to print a copy for yourself!