Parameters in the shell and printing with color

Some function parameters in the shell script are described as follows:

#!/bin/ bash
 echo shows the script itself: $ 0 
echo shows the first parameter: $ 1 
echo shows the number of parameters: $#
 echo concatenates each parameter as a single string: $*
 echo shows the current script running Process id: $$
 echo  "The shift command can remove the first parameter in the parameter list $@, while the rest of the variables are moved forward one place . " 
shift  
echo prints the first parameter after executing the " shift " command $ 1 
echo Display each parameter as a parameter: $@
 echo Display all parameters after the first parameter: ${@: 4 }

Then execute the above script and the result is as follows:

[root@db1 ~]# sh one. sh  1  2  3  4  5  6  7 
show the script itself: one. sh 
show the first parameter: 1 
show the number of parameters: 7 
concatenate each parameter with a single string: 1  2  3  4  5  6  7 
displays the process id of the script currently running: 9691 The 
shift command can remove the first parameter in the parameter list 1 2  3  4  5  6 7, while the rest of the variables are moved forward by one
Print the first parameter after executing the shift command 2 
Display each parameter in the form of parameters: 2  3  4  5  6  7 
Display all parameters after the first few parameters: 5  6  7

When printing with echo, use color printing

Numeric code for text color:

  • reset to 0
  • black    30
  • red       31、
  • green   32
  • yellow   33
  • blue     34
  • Magenta 35
  • Blue 36
  • white    37

Background color number code: the same as the text color, but the number code is different

  • reset to 0
  • black    40
  • red       41、
  • green   42
  • yellow   43
  • blue     44
  • Magenta 45
  • Blue 46
  • white    47

Attribute codes for fonts:

  • 0 turns off all properties
  • 1 Set bold font
  • 4 underscore
  • 5 flashes
  • 7 Invert
  • 8 Blanking

Use a semicolon to separate between background color and number color, and font attributes    !

The last two properties of the font can be tested to see how it works!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324648016&siteId=291194637