Shell quick reference

491 views

Published on

Shell programming cheat sheet

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
491
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Shell quick reference

  1. 1. SHELL PROGRAMMING LOOPINGQUICK REFERENCE GUIDE FOR for variable in file/list doSPECIAL 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 inREGULAR 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)COMMANDSexit code VARIABLE EXPANSIONExit shell with code return code ${var} simple variable substitution ${var:=value}break level assign default value if not definedEscape from level of for or while loop ${var:+value} substitute value if var is non-nullcontinue 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 valuetestEvaluate an expression or conditiontrap Compiled by Michael Oliveri (www.mikeoliveri.com)Used for error handling Feel free to print a copy for yourself!

×