The shell learns to record a

Source: Internet
Author: User

1, the general user's command prompt is the root command prompt is #

2. Each command in bash is separated by semicolons or newline characters, for example

$ cmd1; Cmd2

3, echo each call after the default will add line break, the following can be used in single quotation marks, you can also use double quotation marks, can also be used without quotation marks. Difference is

The ";" variable is not valid in single quotation marks when using echo without single quotation marks, and the variable is usually double-quoted

You cannot print special symbols in double quotes, you need to use escape symbols

4, Echo-e "\e[1;31m here is the content [0m" This means that the color font is displayed, 30,31,32,33,34,35,36,37, respectively, black, red, green, * * *, blue ....

5, Echo-e "\e[1;41m here is the content [0m" This means that the display color background 40,41,42.43,44, respectively, the black, red, green, * * * ....

6, printf can be formatted output, you need to manually enter a line break

printf "%-5s%-10s%-4.2s\n" NO NAME Mark indicates that the setting width is 5, 10 characters, 4.2 means that two decimal places can be reserved--for left alignment, \ n for line wrapping

7. If you want to add a new path in path, use: Export path= "$PATH:/home/usr/bin" can also be used as follows

Path= $PATH:/home/usr/bin

Export $PATH

8, UID can get the ID number of the user, can be viewed directly with the Echo $UID. The root user's UID is 0

9, you can use the shell for digital operations

Method 1, with let, the variable name does not need to add $

No1=1;

nod2=2;

Let RESULT=NOD1+NOD2

Nod self-add operation let nod1++ self-subtract let nod1--

Let no+=6 and let no=no+6 are the same meaning

Method 2, result=$[Nod1 + nod2] or result=$[$nod 1 + 5]

Method 3, result=$ ((nod1 + nod2)) or result=$ (($nod 1 + 5))

Method 4, result= ' expr 3 + 4 ' or result=$ (expr $nod 1 + 5) do not support floating-point numbers for the above calculation methods

Method 5, result= ' echo ' scale=3; $nod 1/$nod 2 "|BC"

Using BC for fractional calculations, scale represents the number of decimal places

echo "obase=10;ibase=2;100" |BC

Converts binary 100 to decimal

10. Document Description and redirection

    • 0---stdin (standard input)

    • 1-----stdout (standard output)

    • 2-----stderr (standard error)

    • CMD 2> error.txt Redirect all errors to Error.txt

    • CMD 2>&1 all.txt Redirect all the outputs to All.txt equals cmd &> all.txt

11. Arrays

Arry_var= (1 2 3 4 5 6)

Prints the element of a specific array echo ${arry_var[1]} with a value of 2

List all values in the array echo ${arry_var[*]} result is 1 2 3 4 5 6

12. Associative arrays

Declare-a Fruites_value

Fruits_value= ([apple]= ' 10yuan ' [orange]= ' 15yuan ')

Display specific array contents echo ${fruits_value[apple]} result is 10yuan

List all index lists echo ${!fruits_value[*]}


This article comes from "If technology can be made into art!" "Blog, be sure to keep this provenance http://jesus110.blog.51cto.com/376008/1575676

The shell learns to record a

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.