Terminal and Bash

master
Gerardo Marx 3 years ago
parent d1f87a749a
commit 03a7967a48

@ -44,7 +44,8 @@ The most used commands at the terminal are listed below. These are know as File
|-------------------|---------|---------------------------------------|----------------------------------| |-------------------|---------|---------------------------------------|----------------------------------|
| | | | | | | | | |
## Terminal ## Configuring the Terminal and Bash
### Terminal
There are several Terminal emulators that will help to visualize and work better during a connection to our local or remote system. There are several Terminal emulators that will help to visualize and work better during a connection to our local or remote system.
I have tested some of them and I can recommend some of they: I have tested some of them and I can recommend some of they:
@ -69,12 +70,128 @@ Once you have decided and installed a terminal emulator, we can start typing com
|---------|------------------------| |---------|------------------------|
| | | | | |
### Bash
Remember that the terminal is the front-end window of the back-end shell system. The system can be Shell, Bash, Fish, Z-Shell, or any other. The most standard used or pre-installed one is the Bash (Bourne-again Shell), Bash is a command processor that typically runs in a text window where the user types commands that cause actions. Bash can also read and execute commands from a file, called a shell script. Like most Unix shells, it supports filename globbing (wildcard matching), piping, here documents, command substitution, variables, and control structures for condition-testing and iteration. The keywords, syntax, dynamically scoped variables and other basic features of the language are all copied from sh. Other features, e.g., history, are copied from csh and ksh. Bash is a POSIX-compliant shell, but with a number of extensions. Remember that the terminal is the front-end window of the back-end shell system. The system can be Shell, Bash, Fish, Z-Shell, or any other. The most standard used or pre-installed one is the Bash (Bourne-again Shell), Bash is a command processor that typically runs in a text window where the user types commands that cause actions. Bash can also read and execute commands from a file, called a shell script. Like most Unix shells, it supports filename globbing (wildcard matching), piping, here documents, command substitution, variables, and control structures for condition-testing and iteration. The keywords, syntax, dynamically scoped variables and other basic features of the language are all copied from sh. Other features, e.g., history, are copied from csh and ksh. Bash is a POSIX-compliant shell, but with a number of extensions.
#### Task 2: Displaying current Bash prompt (PS1)
By following the tutorial from [^1], the `echo` command/`printf` command to display current Bash prompt settings:
``` shell
$ echo "$PS1"
## OR ##
$ printf "%s\n" "$PS1"
```
Here is what I see `%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)`
Here is another output from my Debian based system:
```
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
```
By default the command prompt is set to `[\u@\h \W]\$`. The backslash-escaped special characters are decoded as follows:
- `\u`: Display the current username
- `\h`: Display the hostname
- `\W`: Print the base of current working directory
- `\$`: Display `#` (indicates root user) if the effective UID is 0, otherwise display a `$`.
#### Task 3: Modifing current Bash prompt ####
Before you modify settings save your old prompt using the following command:
``` shell
oldps1="$PS1"
```
So if you messed up, you can switch back easily using the following syntax:
``` shell
PS1="$oldps1"
```
Use the export command to setup a new shell prompt:
``` shell
$ export PS1="[\\u@\\H \\W \\@]\\$ "
```
Where:
- `\H`: Display FQDN (fully qualified domain name) hostname.
- `\@`: Display current time in 12-hour am/pm format.
#### Task 4: Adding colors to the prompt ####
To add colors to the shell prompt use the following export command syntax:
``` shell
'\e[x;ym $PS1 \e[m'
```
Here:
- \e[ : Start color scheme.
- x;y : Color pair to use (x;y)
- $PS1 : Your shell prompt variable.
- \e[m : Stop color scheme.
Change the color of shell prompt by setting the PS1
To set a red color prompt, type the following export command:
$ export PS1="\e[0;31m[\u@\h \W]\$ \e[m "
A list of color codes
| Color | Code |
|--------|------|
| | |
| Black | 0;30 |
| Blue | 0;34 |
| Green | 0;32 |
| Cyan | 0;36 |
| Red | 0;31 |
| Purple | 0;35 |
| Brown | 0;33 |
| Blue | 0;34 |
| Green | 0;32 |
| Cyan | 0;36 |
| Red | 0;31 |
| Purple | 0;35 |
| Brown | 0;33 |
|--------|------|
**Note: You need to replace digit 0 with 1 to get light color version.**
A good and useful prompt extracted from[^2]:
``` shell
PS1="\n \[\033[0;34m\]┌─────(\[\033[1;35m\]\u\[\033[0;34m\])─────(\[\033[1;32m\]\w\[\033[0;34m\]) \n └> \[\033[1;36m\]\$ \[\033[0m\]"
```
#### Task 5: make the prompt setting permanent ####
Your new shell prompt setting set by `$PS1` is temporary i.e. when you logout setting will be lost. To have it set every time you login to your workstation add above export command to your `$HOME/.bash_profile` file or `$HOME/.bashrc` file.
``` shell
$ vi .bash_profile
```
Append the following line:
``` shell
export PS1="\e[0;31m[\u@\h \W]\$ \e[m"
```
### Bash customization with fonts ###
Pending
``` shell
$ mkdir -p .local/share/fonts
$
```
### Package management ###
*** Package management
| Command | Debian | | Command | Debian |
|------------------------------------|----------------------| |------------------------------------|----------------------|
| Install a package | sudo apt install vim | | Install a package | sudo apt install vim |
@ -82,5 +199,10 @@ Remember that the terminal is the front-end window of the back-end shell system.
|------------------------------------|----------------------| |------------------------------------|----------------------|
| | | | | |
*** Basic file editing with VIM ---
*** Expanding the file system
### References ###
[^1]: https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
[^2]: https://drasite.com/blog/Pimp%20my%20terminal

Loading…
Cancel
Save