/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/languages/bash/info.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
WildCards
 
2
=========
 
3
 *, ?, [set], [^set], {variant1,variant2,...}
 
4
 
 
5
variables
 
6
==========
 
7
 ${#var}                - Length of string
 
8
 ${var:FIRST:N}         - Substring
 
9
 ${var:-word}           - var?var:word
 
10
 ${var:+word}           - var?word:null
 
11
 ${var:?mess}           - var?var:abort(mess)
 
12
 ${var#pattern}         - If the pattern matches the beginning of the variable
 
13
                        value, delete the shortest part that matches and return
 
14
                        the rest (shell pattern, not regexp)
 
15
 $(var##pattern}        - Deletes longest part
 
16
 ${var%pattern}         - Shortest part in the end
 
17
 ${var%%pattern}        - Longest part in the end
 
18
 
 
19
 $(( expr ))            - Evaluate expression
 
20
 $(command)             - Equivalent to `command`
 
21
 
 
22
arrays
 
23
======
 
24
 declare -a name
 
25
 name[5]='xxx'
 
26
 
 
27
operators
 
28
=========
 
29
 if cond; then ...; elif cond; then ...; else ...; fi
 
30
 
 
31
 case expression in
 
32
  pattern11|pattern12|... } statements ;;
 
33
  ...
 
34
 esac
 
35
    + Shell patterns are allowable in the patterns.
 
36
 
 
37
 for name [ in list ] ; do statements; done
 
38
 for ((x=1 ; x<3 ; x++ )) do echo $x; done
 
39
 while/until codition ; do statements; done
 
40
    break, continue
 
41
 
 
42
User Interaction
 
43
================
 
44
 select name in xxx zzz quit; do echo $name; done
 
45
    Asks user for selection (in loop)
 
46
 read name                      - Reads line into the $name
 
47
 read a b                       - Read 1st word in to a and rest into b
 
48
 read -t 300 var                - Read with 300 second timeout
 
49
 
 
50
Functions
 
51
=========
 
52
 function funcname {
 
53
    return value
 
54
 }
 
55
 
 
56
Processing Options
 
57
==================
 
58
  $# - Number of arguments
 
59
  $* - All arguments ("$1" "$2" ...)
 
60
  $@ - argument string
 
61
  $$ - pid
 
62
  $! - pid of last background process
 
63
  $- - shell flags
 
64
 
 
65
  while getopts ":ab:c" opt; do
 
66
    case $opt in
 
67
      a) process_option_a;;
 
68
      b) process_option_b
 
69
         $OPTARG is the option's argument;;
 
70
      c) process_option_c;;
 
71
    esac
 
72
  done
 
73
  shift $(($OPTIND - 1))
 
74
 
 
75
Signals
 
76
=======
 
77
    trap "" signal-list         - Ignore signal
 
78
    trap "cmds" signal-list     - Execute commands if signal is caught
 
79
    trap signal-list            - Reset signal to original condition
 
80
    
 
81
 
 
82
Debugging
 
83
=========
 
84
    set -o noexec  sh -n        - Check syntax, don't execute
 
85
    set -o verbose sh -v        - List commands before running
 
86
    set -o xtrace sh -v         - List commands after running
 
87
    set +o <PTION>      - Turns option off
 
88
 
 
89
Tools
 
90
=====
 
91
 wait           - Wait completion of background processing
 
92
 tr             - Translate or delete characters
 
93
 tee            - Read from standrd input and write to stdout and files
 
94
 xargs          - Executes commands on standart input
 
95
    find . -type f -print0 | xargs -0 rm -f
 
96
 seq FIRST INCREMENT LAST       - sequence of numbers