Tag: IDT Test successfully represents the status of LIS sys file one
first edited September 25, 2017 22:43:40
Summary
I. Shell's basic syntax-variables
Two. Shell's basic syntax-operator
Three. Process Control
Homework
Summary today
Summary
Citation: Mr. Haifeng
- Basic syntax of the shell
- Process Control, script transfer
I. Shell's basic syntax-variables
- Naming rules
- Start with a letter
- Connect words with an underscore or an underscore
- The same type is distinguished by numbers
- For file best plus extension
- System variables
- Set and env differences
- Set: Show All variables
- ENV: System Variables
- Assigning values to variables
- unset VARNAME: Deleting variables
- Common system Variables
- PATH
- Pwd
- Lang
- HOME
- Histsize: Number of history log lines
- PS1: Storing user information
- Ifs
- Export: Defining global variables
- Define the bounds of a variable name
[Email protected] ~]# rest_mem=20
[Email protected] ~]# echo ${rest_mem}%
20%
- Data type
Two. Shell's basic syntax-operator
- Arithmetic operators
- Relational operations
- <
- >
- <=
- >=
- ==
- !=
- &&
- ||
- Test command related, [] can achieve the same effect
- Assignment operators
- =
- +=
- *=
- /=
- %=
- [Email protected] ~]# ((x%=3))
[Email protected] ~]# echo $x
- All the calculators in the shell
- $[]
- (())
- $(())
- Expr
- Floating-point arithmetic BC Software
- Yum Install Bc-y
- Echo ' SCALE=2;1/3 ' |bc-l (retains two bits, 1 divided by 3 operations)
- Test action
- After the
- command executes, it returns to a system variable ? & #x5982; & #x679C; Style= "font-size:100%; Display:inline-block; Position:relative "> ? A value of 0 indicates that the command executed successfully or failed
- Testing command test [] [[]] (())
- Test file status
- -D Directory
- -E
- -H Link File
- -S file length > 0, non-empty
- -F Normal File
- -W Writable
- -R Readable
- -X Executable
- -L Symbolic connection
- -u file has suid bit settings
- -B Block File
- String test
- = Two strings equal
- ! = two strings are not equal
- -Z Empty string
- -N Non-empty string
- Test values
- -eq equals
- -ne Not equal to
- -GT Greater than
- -lt less than
- -ge greater than or equal to
- -le less than or equal to
- Expand Test Symbols
Three. Process Control
- The IF statement for Process Control
#!/bin/bashvar=‘/etc/init.d‘#var=‘/dev/sda‘if [ -d $var ] then echo "$var is directory"elif [ -b $var ] then echo "$var is block"elif [ -f $var ] then echo "$var is regular file"else echo ‘unknow‘fi
- Passing parameters to a script
#test.shecho $0echo $1echo $2echo $3echo ${11}echo ‘$$‘ $$echo ‘$*‘ $*echo ‘[email protected]‘ [email protected]echo ‘$#‘ $#echo ‘$?‘ $?‘‘‘测试:python test.sh 1 2 3 4 5 6 7 8 9 10 11输出结果:./test.sh 211$$ 14312$* 1 2 3 4 5 6 7 8 9 10 11[email protected] 1 2 3 4 5 6 7 8 9 10 11$# 11$? 0‘‘‘
* $0 为运行的文件名* $$ 为进程pid* $* 为输入的所有的参数* [email protected] 同$** $# 输入参数个数* $? 上一条命令是否执行成功
- Modify the script so that it can receive the arguments from the caller
[[email protected] ~]# cat test_file.sh#!/bin/bashif [ -d $1 ] then echo "$1 is directory"elif [ -b $1 ] then echo "$1 is block"elif [ -f $1 ] then echo "$1 is regular file"else echo ‘unknown‘fi[[email protected] ~]# ./test_file.sh /etc/passwd/etc/passwd is regular file
- Detects if Nginx is started, and if not, starts it
#! /bin/bashps aux|grep nginx|grep -v grepif [ $? -eq 1 ] then systemctl start nginxfi
Homework
Summary today
Python Full Stack road Day9