Tag:shell reference escape command replace
Escape and reference two types of characters: normal character and escape character escaping: "\" Example: 1, Echo $Dollar 2, echo \ $Dollar 3, Ech O? Characters that need to be escaped: * $ () \ ' "? + ! # & [] {} < > |; /NOTE:!#: reference: Refers to a string enclosed in a symbol to prevent special characters from being parsed into other meanings. Four types: double quotes, single quotes, anti-quotes, escape characters where double quotes are called partial references or weak references, you can reference all characters except $, anti-quotes, escape characters, all characters can be referred to by a single quotation mark, or a strong reference, and an anti-quote interprets the contents of the backslash as a system command. 1, partial reference $, ', \ These three special characters will still be resolved to special characters note: var= "A b C" Echo $VAR;//a B C echo "$VAR";//a B C 2, full reference all characters are ordinary characters echo ' $var ';//$var command substitution: 1, ' Example: var= ' Date ' 2, $ () array is ${} example: var=$ (date) When the command output is multiple rows, if the variable is not output by reference, the output will delete the newline character, and the file name will be populated with the system default NULL, which means that the output contains only one row. Example: #LS = ' LS ' #echo $LS algorithm awk.txt crontab.class Crontab.java crontab.txt #echo "$LS" AlgorIthm awk.txt crontab.class Crontab.java crontab.txt $ () support nesting, while ' unsupported, and ' Single quotes similar, not recommended for complex cases: fir=$ (wc-l $ (ls | sed-n ' 1p '))
Shell Learning Note III (escaping and referencing)