and the echo command shell overview

A, Shell Overview

1. What is the shell?


This shows that the interface shell is the user interacting with the system to complete the processing time by executing various commands and scheduling.

2, shell classification
Shell类别                易学性        可移植性      编辑性      快捷性 
Bourne Shell (sh)          容易          好          较差        较差 
Korn Shell (ksh)           较难          较好         好         较好 
Bourne Again (Bash)         难           较好         好          好 
POSIX Shell (psh)          较难          好          好         较好 
C Shell (csh)               较难         差          较好        较好 
TC Shell (tcsh)              难          差           好          好
The two main types of grammar are Bourne Shell and C, both of grammar is not compatible with each other.

Bourne family including sh, ksh, Bash, psh, zsh.
C family including: csh, tcsh (Bash and zsh support csh syntax to varying degrees).
We can / shells file to query the Linux supported by Shell / etc.

[root@centos ~]# cat /etc/shells 
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

Two, echo commands and shell scripts execution

1, echo output escape special characters
echo [选项] [输出内容] 选项:  
-e: 支持反斜线控制的字符转换
    \\ 输出\本身 
    \a 输出警告音 
    \b 退格键,也就是向左删除键 
    \c 取消输出行末的换行符
    \e ESCAPE 键 
    \f 换页符 
    \n 换行符 
    \r 回车键 
    \t 制表符,也就是 Tab 键 
    \v 垂直制表符 
    \0nnn 按照八进制 ASCII 码表输出字符。其中 0 为数字零,nnn 是三位八进制数 
    \xhh 按照十六进制 ASCII 码表输出字符。其中 hh 是两位十六进制数
-n: 取消输出后行末的换行符号(就是内容输出后不换行)

Examples

[root@centos ~]# echo -e "heihei \nhaha \a" #先输出heihei,换行之后再输出一个 haha 最后输出警示音
heihei 
haha 
2, echo output color
30m=黑色,31m=红色, 32m=绿色,33m=黄色,34m=蓝色,35m=洋红,36m=青色,37m=白色
1)字体颜色
echo -e "\e[1;32m 绿色字体 \e[0m"

2)背景颜色
echo -e "\e[1;42m 绿色背景 \e[0m"

3)闪烁
echo -e "\e[1;5m \e[1;32m 绿色闪烁字体 \e[0m  \e[0m" 
3, execute the shell script

There are two ways to execute a shell script, here is a simple shell script:

#!/bin/bash   #直接执行时,告诉系统应该用哪一个解释器来执行。
echo -e "\e[1;5m \e[1;32m 你好!! \e[0m  \e[0m"
  • The first execution, direct execution
    execute permission, use a relative or absolute path to execute
[root@centos ~]# chmod a+x test.sh 
[root@centos ~]# . test.sh 
  你好!
[root@centos ~]# /root/test.sh 
  你好! 
  • + Script executed using an interpreter way, do not need to add execute permissions.
[root@centos ~]# bash test.sh 
  你好!

Guess you like

Origin www.cnblogs.com/hjnzs/p/12078687.html