Python Full Stack road Day9

Source: Internet
Author: User
Tags arithmetic arithmetic operators ord

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

    1. Basic syntax of the shell
    2. Process Control, script transfer
I. Shell's basic syntax-variables
    1. Naming rules
      1. Start with a letter
      2. Connect words with an underscore or an underscore
      3. The same type is distinguished by numbers
      4. For file best plus extension
    2. System variables
      • Set and env differences
      • Set: Show All variables
      • ENV: System Variables
    3. Assigning values to variables
      • unset VARNAME: Deleting variables
    4. Common system Variables
      • PATH
      • Pwd
      • Lang
      • HOME
      • Histsize: Number of history log lines
      • PS1: Storing user information
      • Ifs
      • Export: Defining global variables
    5. Define the bounds of a variable name
      [Email protected] ~]# rest_mem=20
      [Email protected] ~]# echo ${rest_mem}%
      20%
    6. Data type
Two. Shell's basic syntax-operator
  1. Arithmetic operators
    • +
    • -
    • *
    • /
    • %
  2. Relational operations
    • <
    • >
    • <=
    • >=
    • ==
    • !=
    • &&
    • ||
      • Above with (())
    • Test command related, [] can achieve the same effect
  3. Assignment operators
    • =
    • +=
    • *=
    • /=
    • %=
    • [Email protected] ~]# ((x%=3))
      [Email protected] ~]# echo $x
  4. 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)
  5. Test action
    1. After the
    2. 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
    3. Testing command test [] [[]] (())
      1. 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
      2. String test
        • = Two strings equal
        • ! = two strings are not equal
        • -Z Empty string
        • -N Non-empty string
      3. 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
      4. Expand Test Symbols
Three. Process Control
    1. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.