際際滷

際際滷Share 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!
Ad

Recommended

Shell Scripting Structured Commands
Shell Scripting Structured Commands
Don Bosco BSIT
Vi CheatSheet
Vi CheatSheet
framinazzi
Regular expressions in Perl
Regular expressions in Perl
Girish Manwani
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
sana mateen
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
heoff
Cold fusion best practice
Cold fusion best practice
isummation
Subroutines in perl
Subroutines in perl
sana mateen
Polarion Conf 2012 - Come Emerasoft ti veste Polarion
Polarion Conf 2012 - Come Emerasoft ti veste Polarion
Emerasoft, solutions to collaborate
00 ruby tutorial
00 ruby tutorial
Walker Maidana
Introduction to shell
Introduction to shell
Arash Haghighat
Shell scripting
Shell scripting
Mufaddal Haidermota
Complete Overview about PERL
Complete Overview about PERL
Ravi kumar
Php Chapter 4 Training
Php Chapter 4 Training
Chris Chubb
429 e8d01
429 e8d01
vipinck2008
003 scripting
003 scripting
Sherif Mousa
newperl5
newperl5
tutorialsruby
newperl5
newperl5
tutorialsruby
perl-regexp-refcard-a4
perl-regexp-refcard-a4
tutorialsruby
perl-regexp-refcard-a4
perl-regexp-refcard-a4
tutorialsruby
SUSE Linux quick reference
SUSE Linux quick reference
Alessandro Grandi
Linux quick reference
Linux quick reference
Alessandro Grandi
Lvm cesvip
Lvm cesvip
Alessandro Grandi
Cesvip 2010 first_linux_module
Cesvip 2010 first_linux_module
Alessandro Grandi
Cesvip 20110127
Cesvip 20110127
Alessandro Grandi
Cesvip 20110124
Cesvip 20110124
Alessandro Grandi
Cesvip 20110120
Cesvip 20110120
Alessandro Grandi

More Related Content

Similar to Shell quick reference (11)

00 ruby tutorial
00 ruby tutorial
Walker Maidana
Introduction to shell
Introduction to shell
Arash Haghighat
Shell scripting
Shell scripting
Mufaddal Haidermota
Complete Overview about PERL
Complete Overview about PERL
Ravi kumar
Php Chapter 4 Training
Php Chapter 4 Training
Chris Chubb
429 e8d01
429 e8d01
vipinck2008
003 scripting
003 scripting
Sherif Mousa
newperl5
newperl5
tutorialsruby
newperl5
newperl5
tutorialsruby
perl-regexp-refcard-a4
perl-regexp-refcard-a4
tutorialsruby
perl-regexp-refcard-a4
perl-regexp-refcard-a4
tutorialsruby

More from Alessandro Grandi (7)

SUSE Linux quick reference
SUSE Linux quick reference
Alessandro Grandi
Linux quick reference
Linux quick reference
Alessandro Grandi
Lvm cesvip
Lvm cesvip
Alessandro Grandi
Cesvip 2010 first_linux_module
Cesvip 2010 first_linux_module
Alessandro Grandi
Cesvip 20110127
Cesvip 20110127
Alessandro Grandi
Cesvip 20110124
Cesvip 20110124
Alessandro Grandi
Cesvip 20110120
Cesvip 20110120
Alessandro Grandi
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!