The following post will guide you through the secrets behind BASH and allow you to get the maximum from this shell.
Bash Completion
Complete – command line to load command completion with tab.
Complete –p : shows all custom completion
/etc/bash_completion
Compgen – gets list of values with prefix for each and gets the user input and completes all started with this phrase.
Compgen –W “—param1 –param2 …” – “—paramx”
This command working by itself.
Variables:
COMPREPLY –
COMP_WORDS
COMP_WORD
Complete –F _function command
http://www.debian-administration.org/article/316/An_introduction_to_bash_completion_part_1
General
multiple conditions on bash – [[ condition1 && condition2 ]].
Scripting
IFS
IFS=$’\n’
Arrays
About arrays: http://tldp.org/LDP/abs/html/arrays.html
Array Length: http://www.cyberciti.biz/faq/finding-bash-shell-array-length-elements/
List to array:
http://stackoverflow.com/questions/9736202/bash-read-tab-separated-file-line-into-array
http://stackoverflow.com/questions/9293887/in-bash-how-do-i-convert-a-space-delimited-string-into-an-array
Find the highest number: http://stackoverflow.com/questions/12744245/bash-how-to-find-the-highest-number-in-array
For loop from start to end: http://stackoverflow.com/questions/6191146/variables-in-bash-seq-replacement-1-10
Shell Variables
Shell variables are variables only reachable at the current shell. No child will be able to read this variable.
<varname>=<value>
Environment Variables
Those variables are reachable both at the current shell and in the subsequent shells.
Export <varname>[=<value>]
Export –n <varname> – will turn environment variable into shell variable
Unset <varname> – delete the variable
Shortcut keys
Ctrl + A | Go to the beginning of the line you are currently typing on |
Ctrl + E | Go to the end of the line you are currently typing on |
Ctrl + L | Clears the Screen, similar to the clear command |
Ctrl + U | Clears the line before the cursor position. If you are at the end of the line, clears the entire line. |
Ctrl + H | Same as backspace |
Ctrl + R | Let’s you search through previously used commands |
Ctrl + C | Kill whatever you are running |
Ctrl + D | Exit the current shell |
Ctrl + Z | Puts whatever you are running into a suspended background process. fg restores it. |
Ctrl + W | Delete the word before the cursor |
Alt + D | Delete the word after the cursor |
Ctrl + K | Clear the line after the cursor |
Ctrl + T | Swap the last two characters before the cursor |
Esc + T | Swap the last two words before the cursor |
Alt + F | Move cursor forward one word on the current line |
Alt + B | Move cursor backward one word on the current line |
Tab | Auto-complete files and folder names |