bash logo

Nice Tips&Tricks for bash environment


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


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.







Complete –F _function command


multiple conditions on bash – [[ condition1 && condition2 ]].






About arrays:

Array Length:

List to array:

Find the highest number:

For loop from start to end:

Shell Variables

Shell variables are variables only reachable at the current shell. No child will be able to read this variable.


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


Leave a Reply

Your email address will not be published. Required fields are marked *