当前位置:网站首页>ba_ Shell learning summary

ba_ Shell learning summary

2022-07-23 05:12:00 IC fragmentary thoughts

ba-shell Learning summary

Tags: script

shell What is it? ?

shell It's a command line interpreter , Provides users with a way to linux The kernel sends requests to run the program's interface system level program , User available shell To start up , Hang up , Stop even writing programs

 Insert picture description here

shell classification :c_shell,z_shell,ba_shell

How the script is executed

  • The script needs to #!/bin/bash start
  • Scripts require executable permissions + X perhaps sh + xxx.sh perform .

Shell A variable is introduced

  • Subsystem variables and user-defined variables ,
  • System variables :$HOME $PWD $SHELL U S E R etc. etc. can use s e t display in the Yes Of system system change The amount “ USER wait You can use set Display all system variables “ USER etc. etc. can use set display in the Yes Of system system change The amount ” Used to represent variable substitution
  • User customization : Variable name ( Do not start with a number , Capitalization )= value (= There must be no space between ) A=10
  • Revoke variables :unset + Variable unset A
  • Declare static variables :readonly Variable , Be careful : You can't unset
  • take The return value of the command Assigned to a variable A=’date’ or A=$(date)
  • take shell Variable output is environment variable / Global variables ( The whole picture is visible , Available variables ) export Variable name = value /etc/profile
  • Let the modified profile take effect immediately source The configuration file source /etc/profile
  • Multiline comment :<<! xxxx !
  • Positional arguments $0 To express an order $1 Represents the first parameter ... 9 surface in The first 9 individual ginseng Count . 9 It means the first one 9 Parameters . 9 surface in The first 9 individual ginseng Count .# Indicates the number of parameters
  • Operator writing REST1= ( ( 2 + 3 ) ) R E S T 2 = ((2+3)) REST2= ((2+3))REST2=[2+3] REST3= expr 2 + 3

grammar

  • conditional
     Insert picture description here
    1): = String comparison judgment statement :
    2): A comparison of two integers
    -lt Less than little

    -le Less than or equal to
    -eq be equal to equal
    -gt Greater than

    -ge Greater than or equal to

    -ne It's not equal to

    3): Judge according to the file authority
    -r Have read permission
    -w Have the right to write
    -x Have the authority to execute

    4): Judge according to the document type
    -f The file exists and is a regular file
    -e File exists

    -d The file exists and is a directory

    if [ "ok" = "ok" ]
    then
    		echo "equal"
    fi
    
    if [ -f /root/shcode/aaa.txt ]
    then
    		echo "exist"
    elif
    		echo "not exist "
    fi
    
    
  • case sentence
     Insert picture description here

    case $1 in   # Positional arguments 
    "1")
    echo " Monday “ ;; "2") echo " Tuesday " ;; *) echo "other..."
    ;;
    esac #case  Write back 
    
  • For loop
     Insert picture description here

  • while loop
     Insert picture description here

  • read Read console input
     Insert picture description here

    read -p " Please enter a num" NUM -t 10
    echo " Input num=$NUM"
    
  • Custom function
     Insert picture description here
     Insert picture description here

    Learn to refer to teacher Han Shunping's video ( Attached video address )
    https://www.bilibili.com/video/BV1Sv411r7vd?p=107&spm_id_from=pageDriver

原网站

版权声明
本文为[IC fragmentary thoughts]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207221753242169.html