| 1 | <h2>Shebang</h2> |
| 2 | <pre><code>#!/bin/bash</code></pre> |
| 3 | |
| 4 | <h2>Comments</h2> |
| 5 | <pre><code># This is a comment</code></pre> |
| 6 | |
| 7 | <h2>Strings</h2> |
| 8 | <pre><code>STRING="Hello World" |
| 9 | 'Single and |
| 10 | multi-line strings are supported.' |
| 11 | "Single and |
| 12 | multi-line strings are supported." |
| 13 | cat << EOF |
| 14 | Here-Documents |
| 15 | are also supported |
| 16 | EOF</code></pre> |
| 17 | |
| 18 | <h2>Variables</h2> |
| 19 | <pre><code>echo $STRING |
| 20 | args=("$@") |
| 21 | echo ${args[0]} ${args[1]} ${args[2]}</code></pre> |
| 22 | |
| 23 | <h2>Keywords</h2> |
| 24 | <pre><code>for (( i=0;i<$ELEMENTS;i++)); do |
| 25 | echo ${ARRAY[${i}]} |
| 26 | done |
| 27 | while read LINE; do |
| 28 | ARRAY[$count]=$LINE |
| 29 | ((count++)) |
| 30 | done |
| 31 | if [ -d $directory ]; then |
| 32 | echo "Directory exists" |
| 33 | else |
| 34 | echo "Directory does not exists" |
| 35 | fi |
| 36 | </code></pre> |
| 37 | |
| 38 | <h2>Some well-known commands</h2> |
| 39 | <pre><code>crontab -l -u USER | grep -v 'YOUR JOB COMMAND or PATTERN' | crontab -u USER - |
| 40 | |
| 41 | groups user1 user2|cut -d: -f2|xargs -n1|sort|uniq -d |
| 42 | |
| 43 | wget -q -O - http://www.example.com/automation/remotescript.sh | bash /dev/stdin parameter1 parameter2 |
| 44 | |
| 45 | sudo dpkg -i vagrant_1.7.2_x86_64.deb |
| 46 | |
| 47 | git pull origin master |
| 48 | |
| 49 | sudo gpg --refresh-keys; sudo apt-key update; sudo rm -rf /var/lib/apt/{lists,lists.old}; sudo mkdir -p /var/lib/apt/lists/partial; sudo apt-get clean all; sudo apt-get update</code></pre> |