Bash
Categories:
Bash is the default shell for almost all the Linux distributions. It also supports a bash scripting language.
Bash can be executed in interactive mode or non-interactive mode.
- In interactive mode, it is basically the shell we are talking about every single day. You can issue commands in it, and then expect output.
- In non-interactive mode, it will execute a bash script file.
Although bash supports script, it is not recommended to use bash to do your automation unless you have to. Most of the time, I still use python, because python is way easier to understand and manage.
If you used bash before, you must know that you can use bash to execute a lot of commands, e.g., ls, cat, grep. Note that none of these commands are bash built-in commands (i.e., compiled into the bash binary). They are just separate tool running in separate process. So I’m not going to include them in this article.
Useful Operations
Using bash is pretty straightforward. There is not too much to talk about, but you do want to remember the following hotkeys to make you efficient:
ctrl + a
: go to the beginning of the line.ctrl + e
: go to the end of the line.ctrl + k
: delete all chars to the right of the cursor.ctrl + l
: clear screen (any time).ctrl + r
: search previous commands.ctrl + /
: undo.<up>
: the previous command (if there is any).<down>
: the next command (if there is any).ctrl + c
: sends SIGINT to your running program.ctrl + \
: sends SIGQUIT to your running program (this is more powerful thanctrl+c
).
Recommended Config
A lot of the Linux distributions come with a decent default bash config, which is already good enough. If yours doesn’t, make sure at least you have a color prompt for your bash with the following config:
PS1='\[\e]0;\w\a\]\[\e[38;2;32;181;255m\]\u@\h:\w$\[\e[0m\] '