Shell Step by Step (2) -- Variable, stepvariable

Source: Internet
Author: User

Shell Step by Step (2) -- Variable, stepvariable
3. Variable declaration readonly read-only export modification or printing environment variable export-p display current environment
[Note] Note that there must be no spaces before and after the assignment.
# Echo Control Character Color root @ kallen:/home/kallen/TEST/Shell # echo-e '\ e [1; 31 mHello, World \ e [0m'
Hello, World background color: 0 transparent (Use Terminal color), 40 black, 41 red, 42 green, 43 yellow, 44 Blue 45 purple, 46 green, 47 white (Gray) foreground color: 30 Black 31 red, 32 green, 33 yellow, 34 blue, 35 purple, 36 green, 37 white (Gray) High Brightness: highlight is 1, do not highlight is 0. Note that m follows the string.
-E is used to enable escape \ e or \ 033 in echo to output the Esc symbol to set the color format: \ e [background color; foreground color; highlight m Restore Default is \ e [0 m highlight is 1, not highlighted is 0 note m followed by string
[Note] When "-" is used as the redirection operator for file names starting with "-", problems may occur. you should write a script to check the problem and add a proper prefix to the file. for example :. /-FILENAME, $ PWD/-FILENAME, or $ PATHNAME/-FILENAME. if the variable value starts with "-", it may also cause problems. 1 var = "-n" 2 echo $ var3 # has the "echo-n" effect, so nothing will be output.

~ + The current working directory is equivalent to the $ PWD variable .~ -The previous working directory is equivalent to the internal variable $ OLDPWD. = ~ This operation is used for regular expressions. This operation will be explained in the regular expression matching section. Only version3 supports. ^ The first line. The regular expression indicates the first line. "^" locates the first line.
Variable Assignment Method -- (1) direct assignment: = (2) Let assignment: let a = 16 + 5
Bash does not distinguish variables from "type ". basically, Bash variables are strings. however, it depends on the context. Bash also allows comparison and arithmetic operations. the key factor is whether the value in the variable is only a number.
A. Location Parameter {} is a good way to use location parameters. This also requires indirect reference of 1 args =$ # Number of location parameters 2 lastarg =$ {! Args} 3 # Or: lastarg =$ {! #}4 # Note lastarg =$ {! $ #} Will report an error

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.