Linux learning-command line parameters, functions

Shell

Command line parameters

  • Command line parameters can be read using $ 1 $ 2 ... $ {10} .. $ n
  • $ 0 represents the script name
  • $ * And $ @ represent all positional parameters
  • $ # Represents the number of positional parameters

function

  • function fname () {
    Command
    }

  • Function execution:

    • fname
    • Cancel a function: unset fname

Variable of function scope

  • local variable names only work inside functions

Function parameters

  • $1 $2 $3...$n

System function library

  • /etc/init.d/functions Function library built by the system
  • / etc / profile stores system environment variables
  • Both .bashrc and .bash_profile have functions that determine the execution order of the program. Both files are under the home directory of the root directory

Self-built function library

  • Use the source function script file to "import" the function
    • source /etc/init.d/functions

Scripting to capture signals

  • kill sends signal 15 to the application by default
  • Ctrl + c Send No. 2 signal to the application
  • No. 9 signal cannot be blocked
  • Example:
    • trap "echo sig 15" 15 capture the 15th signal, output sig 15 if it is captured

Guess you like

Origin www.cnblogs.com/chenri/p/12677415.html