First, what is the shell?
The shell is a command-line interpreter that provides users with an interface system-level program that sends a request to the Linux kernel to run the program, and the user can start, suspend, or even write some programs with the shell. The shell is also a powerful programming language, easy to write, easy to debug, and highly flexible. The shell is the scripting language that interprets execution, and the Linux system commands can be invoked directly in the shell.
Second, the shell classification
1, Bourne Shell: short: B shell, since 1979 UNIX began to use Bourne shell,b Shell's main file suffix is. Sh,bshell does not support history. Mainly include: sh, Bash, PSH, zsh.
2, C Shell:c Shell is mainly used in the BSD version of UNIX system, its syntax and C language similar to the name. Cshell mainly includes: Csh,tcsh.
3. Shows what version of the shell is being used in the current system. For example: Echo $SHELL
4. Displays all supported shells in the current system. Example: Cat/etc/shells
5. Switch to a different shell to use the shell's name directly. For example: Bash, sh, and so on. Exit the shell.
Iii. How shell scripts are executed
1. Echo: Indicates the output of a word in the console. If the output contains spaces, double quotation marks must be used, and special characters can be used if the-e option is used in echo.
Control characters |
Role |
\a |
Output warning tone |
\b |
Show Backspace key |
\ n |
Line break |
\ r |
Enter |
\ t |
Tabs. |
\v |
Vertical tab |
\0nnn |
Output characters according to octal ASCII, where 0 is a digital zero and NNN is a three-bit octal number. Example: Echo-e "\0123" Display uppercase S |
\xhh |
Output characters in hexadecimal ASCII, where HH is a two-bit hexadecimal number. Example: Echo-e "\x61" shows lowercase a |
\e[1;31m \e[0:m |
A string that displays the output through color. Color list: #30m = Black #31m = Red #32m = Green #33m = Yellow #34m蓝色 #35m = Magenta #36m = Cyan #37m = White For example: Echo-e "\e[1;31mhello world\e[0m" with red output Hello world. |
2. Define the script:
A, create a hello.sh text file;
b, and then start with #!/bin/bash, where the declaration of the script must be added.
c, output instructions. The # in the instruction indicates the meaning of the comment.
Cases:
#!/bin/bash#myFirst program! Echo " \e[1;31mhello wolrd\e[0m"
3. Execute script
A. Execute scripts directly using bash hello.sh, but this is inconvenient and the advantage is that you do not need to give script execution permissions.
B. First give the script execute permission before executing the script. Execution is convenient, the disadvantage needs to be manually assigned EXECUTE permission.
chmod 775 Hello. SH . /hello. SH
Linux Learning Notes (eight) shell overview