SlideShare uma empresa Scribd logo
1 de 1
Baixar para ler offline
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!

Mais conteúdo relacionado

Semelhante a Shell quick reference

Semelhante a Shell quick reference (11)

00 ruby tutorial
00 ruby tutorial00 ruby tutorial
00 ruby tutorial
 
Introduction to shell
Introduction to shellIntroduction to shell
Introduction to shell
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Complete Overview about PERL
Complete Overview about PERLComplete Overview about PERL
Complete Overview about PERL
 
Php Chapter 4 Training
Php Chapter 4 TrainingPhp Chapter 4 Training
Php Chapter 4 Training
 
429 e8d01
429 e8d01429 e8d01
429 e8d01
 
003 scripting
003 scripting003 scripting
003 scripting
 
newperl5
newperl5newperl5
newperl5
 
newperl5
newperl5newperl5
newperl5
 
perl-regexp-refcard-a4
perl-regexp-refcard-a4perl-regexp-refcard-a4
perl-regexp-refcard-a4
 
perl-regexp-refcard-a4
perl-regexp-refcard-a4perl-regexp-refcard-a4
perl-regexp-refcard-a4
 

Mais de Alessandro Grandi

Mais de Alessandro Grandi (7)

SUSE Linux quick reference
SUSE Linux quick referenceSUSE Linux quick reference
SUSE Linux quick reference
 
Linux quick reference
Linux quick reference Linux quick reference
Linux quick reference
 
Lvm cesvip
Lvm cesvipLvm cesvip
Lvm cesvip
 
Cesvip 2010 first_linux_module
Cesvip 2010 first_linux_moduleCesvip 2010 first_linux_module
Cesvip 2010 first_linux_module
 
Cesvip 20110127
Cesvip 20110127Cesvip 20110127
Cesvip 20110127
 
Cesvip 20110124
Cesvip 20110124Cesvip 20110124
Cesvip 20110124
 
Cesvip 20110120
Cesvip 20110120Cesvip 20110120
Cesvip 20110120
 

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!