Shell Basics-Bash basic features

Source: Internet
Author: User

  1. Historical command History
    Option:-C Empty History command-W Save History Command now
    The history command entered under Linux will be saved in the root directory: ~/root/.bash_history file
    Save 1000 by default to modify environment variables in the/etc/profile file
    !ser: Executes the last command that begins with Ser
    !! : Executes the previous command again
  2. Defining aliases
    # alias VI = "VIM"//reboot system disappears
    # Unalias VI
    Permanent effect
    # VI/ROOT/.BASHRC
  3. Output redirection
    Standard output redirection: command > File override Way command >> file append way
    Standard error Output redirect: Error command 2> file Overwrite method error command 2>> file Append method
    A. Save the correct output and error output to the same file in a covered manner
    Format: command > File 2>&1
    Commands &> Documents
    B. Append the correct output and error output to the same file in Append mode
    Format: Command >> file 2>&1
    Commands &>> Documents
    C, append the correct output to the file 1, error output appended to the file 2
    Format: Commands >> files 1 2>> file 2
  4. Script Execution Connector
    ; Perform the order of eg: command 1; Command 2
    && the previous command executed successfully and then executes the next eg: Command 1&& command 2
    || Previous command execution failed to execute eg: command 1| | Command 2
    | Correct output of command 1 as a command two-action object eg: command 1| Command 2
  5. grep command
    # grep [Options] "Search content" file
    Options:
    -I: Ignore case
    -N: Output line number
    -V: Reverse Lookup
    –color=auto search keywords are displayed in color
  6. Custom variables
    Variables can consist of letters, numbers, underscores, but cannot start with a number
    The type of the variable defaults to the string type, and if a numeric operation is required, the variable type must be modified to be numeric
    The variable is connected by an equal sign, the equals 2 edges cannot have spaces, and if the variable value has a space, a single quotation mark is used to include
    If you need to increase the value of the variable, the variable needs to be enclosed in double quotation marks: "$ variable name" or with ${variable name} containing
    If you assign the result of the command as a variable value, you need to use the inverse quotation mark or the $ () containing command
    Variable settings: a=123
    Variable invocation: Echo $name
    Variable view: Set
    Variable deletion: unset name
  7. Pre-defined variables

    Pre-defined variables Role
    $? The return status of the last command executed. If the value of this variable is 0, it proves that the previous command was executed correctly, and if the value of the variable is not 0, the previous command was executed incorrectly. (Echo $?)
    $$ Process number (PID) of the current process
    $!

    Process number (PID) of the last process running in the background


    Receive keyboard input
    # read [options] [variable name]
    Options:
    -P "prompt message" when waiting for the read input, the output prompt message
    -T number of seconds the read command waits for user input, specifying the wait time
    -N Characters The read command will only accept the specified number of characters, and it will execute
    -s hides input data for password input
    code example:

    #! /bin/Bash Read-TTen-P"Please input your name:"name# Prompt Please enter name, wait 10 seconds, save user input to variable name nameEcho "Name is $name"Read-s-tTen-P"Please enter your age:"age# age is privacy, with"- S"option to hide inputEcho-E"\ n"Echo "Age is $age"Read-N1-TTen-P"Please select gender[m/f]:"gender# Use"- N 1"option to receive only one input character will be executed (no carriage return)Echo-E"\ n"Echo "Sex is $gender"
    Code
  8. Declare declaring variable types

    # DECLARE [+/-] [option] Variable name

    Options:

    -: Set type attribute to variable

    +: Cancels the Type property of a variable

    -I: Declaring a variable as an integer

    -x: Declaring a variable as an environment variable

    -P: Displays the declared type of the specified variable

    Other methods: Numeric operations using: CC = $ (($aa + $bb) or CC = $[$aa + $BB]

Shell Basics-Bash basic features

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.