Variables of Shell programming

Source: Internet
Author: User

  • Shell Basics

    • What is a shell?
      • Shell is a command-line interpreter
      • The shell is also a very powerful programming language that can invoke Linux commands directly in the shell
    • How the script executes
      • Give execute permission to run directly
        • chmod 755 hello.sh
        • ./hello.sh
      • Execute script via bash call
        • Bash hello.sh
    • Output redirection
      • Commands > Documents
      • Output the correct output of the command to the specified file in a covered manner
      • Commands >> Documents
      • Output the correct output of the command to the specified file in an additional way
    • Sequential execution between multiple commands
      • Command 1; Command 2
      • Multiple command order execution, no logical connection between commands
      • Command 1 && Command 2
      • Command 1 executes correctly, then command 2 executes
      • Command 1 does not execute correctly, then command 2 does not execute
      • Command 1 | | Command 2
      • Command 1 does not execute correctly, then command 2 executes
      • Command 1 is executed correctly, then command 2 does not execute
    • Pipe character
      • Command 1 | Command 2
  • Variables of Shell programming

    • Variable command rules
      • The variable name must begin with a letter or underscore, and the middle of the name can consist only of letters, numbers, and underscores
      • In bash, the default type of the variable is the string type
    • Classification of variables
      • User-defined variables: variable-Custom
      • Environment variables: Data variables related to the operating environment of the system
      • Positional parameter variable: A parameter used to pass parameters to a script.
      • Predefined variables: Variables that are already defined in bash, variables cannot be customized, and variables are fixed
    • Defining variables
      • Variable name = variable Value
        • X=5
        • Name= "Jeff Wang"
      • The left and right sides of the equals sign are not allowed to have spaces, and the system will think that this is a command
      • If there are spaces in the variable, be sure to enclose the double or single quotation marks
    • Variable invocation
      • echo $ variable Name
        • Echo $x
        • Echo $name
    • Variable Overlay
      • X=123
      • x= "$x" 456
      • x=${x}789
    • Variable view
      • Set-u
      • If this option is set, an error will be made when a variable is called without declaring it (no hint by default)
    • Variable deletion
      • unset variable Name
      • Be aware that the variable name is not $
        • unset x
        • unset name
    • Environment variables
      • The main difference between an environment variable and a user-defined variable is that the environment variable is a global variable, and the user-defined variable is a local variable
      • Variables can be customized, but the environment variable names and variables that are in effect on the system are fixed
    • Setting environment variables
      • Export variable name = variable Value
      • Or
      • Variable name = variable Value
      • Export variable Name
    • View environment variables
      • Set
        • View all variables
      • Env
        • View environment variables
    • Common environment variables
      • Shell: the current shell
      • Term: Terminal environment
      • Histsize: Number of history command bars
      • Ssh_client: The current operating environment is connected by SSH, where the client IP is logged
      • Ssh_tty:ssh the terminal when connected
    • PATH environment variable
      • Path variable: Paths to System lookup commands
      • Echo $PATH
      • Path= "$PATH":/root/sh
        • Increase the value of the PATH variable
    • PS1 Environment variables
      • PS1 variables: Command prompt settings
        • \u: Displays the current user name
        • \w: Displays the full name of the current directory
        • []\u[]@[]\h[]:[]\w[]$
      • Ls
        • Line break, command too long not to lose the situation
    • Positional parameter variables
      • $n
      • $*
      • [Email protected]
      • $#
    • Pre-defined variables
      • $?
      • $$
      • $!
    • You can use man bash to query the role of positional parameter variables and predefined variables
    • Receive keyboard input
      • read [options] [variable name]
  • environment variable configuration file
    • Source Configuration file
    • Or
    • . Configuration file
      • Note there is a space between the point and the configuration file, where the dot is equivalent to source
    • After you modify the configuration file, you must log off to log on again to take effect, and use the source command to log back on
    • Introduction to the configuration file
      • /etc/profile
      • /etc/profile.d/*.sh
      • ~/.bashrc
      • /etc/bashrc
      • Different system file names may be different, but this should be the location
      • You should be able to read these shell script roughly.

Variables of Shell programming

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.