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