Or return to our Command Line ... After the two chapters, it should be very clear when you hit the keyboard behind the shell prompt until the Enter is pressed, the text you entered is Command Line, and then shell The command you handed over with the itinerary. However, you can know: Every text you entered in Command Line, is there a category of the shell? Simple (I don't dare to say this is accurate to expose, note one), each Charactor of Command Line is divided into the following two: * literal: It is ordinary pure text, there is no special function for the shell. * Meta: Special reserves with specific functions for Shell. (Note: About Bash Shell's order description when processing Command Line, please refer to O'Reilly Press Learning The Bash Shell, 2nd Edition, No. 177 - 180 Page, especially on page 17 Foundation Figure 1 ...) Litral has no tang, where ABCD, 123456 these "text" are literal ... (easy?) But Meta often makes us confused ..... (confused?) In fact, before Two chapters we have encountered two machines that have encountered two machines in Command Line, which is composed of
In Bash, common quoting has three methods: * Hard quote: '' (single number), all METAs in Hard Quote are closed. * Soft Quote: "" (Double Quotes), large part of Meta in Soft QuoE will be turned off, but some are reserved (such as $). (Note) * escape: / (reverse slope), only close Meta immediately after Escape (Jumk) is closed. (Note: In the case of the specific meta list of Soft Quote, I don't fully know that if you need to make up, or through the practice to find and understand.) The following example will help our understanding: Code: $ A = BC # blank key is not turned off, as IFS processing. $ C: Command Not Found. $ ECHO $ A $ A = "B C" # blank key has been turned off, only a blank key process. $ Echo $ A B C
When setting the A variable for the first time, since the blank key is not closed, Command Line will be interpreted as: * a = b and then touch
Code: $ a = 'b> c>' $ echo "$ a" b c
In the above example, since
Code: $ a = "b> c>" $ ECHO $ A B C
However, since the variables at ECHO $ A are not in Soft Quote, when the variable is completed,
Code: $ a = b /> c /> $ ECHO $ A BC
In the above example, the first
In the first echo command line, the $ Soft Quote will not be closed, thus continuous processing variable replacement, so the ECHO outputs A to the screen, which also obtains the result of "B C". In the second echo command line, the $ is placed in the hard quote, so $ is just a $ symbol, and it is not used to make a variable replacement process, so the result is the next A letter behind: $ A. -------------------------------------- Practice and Thinking: Why is the following results?
Code: $ a = b / c $ echo '"$ a"' # The outermost is single quotes "$ a" $ echo "'$ a'" # outer is double quotes 'bc' (Tip: single quotes And double quotes, are all closed in quoting? # 93 ;.)
-------------------------------------- In the shell version of CU, I found a lot of beginners. The problem is related to the QUOTING. For example, if we call some variables before the parameters of the AWK or SED, will often ask why it is impossible. To resolve these issues, the key points are: * Distinguish the Meta we mentioned in front of Shell Meta and Command Meta, all of which have special purposes in Command Line, ratio {} is placed in one series of Command Line The unnamed functions (can be simply treated as Command Block), but AWK needs to distinguish the AWK command segment (Begin, Main, End) with {}. If you enter this in Command Line:
Code: $ awk {print $ 0} 1.txt
Since {} is not closed in the shell, the shell will treat {Print $ 0} as a Command Block, but at the same time, there is no ";" symbol as a command area, therefore, the AWK's syntax error result. To solve it, use hard quote:
Code: $ awk '{print $ 0}' 1. The hard quote above the TXT should be understood, which is to close the original {,
Code: awk "{print / $ 0}" 1.txt awk / {print / / / $ 0 /} 1.txt
However, if you want to change the 0 value of the $ 0 in AWK is read from another shell variable? For example: The value of the variable $ A is 0, how do you solve the AWK $$ in Command Line? You can directly deny the Solution of Hard QuoE:
Code: $ awk '{print $$ a}' 1.txt
That is because $ A of $ A is not replaced in Hard Quote. Smart readers (such as you!), After learning this chapter, I think, you should explain why we can use the following:
Code: A = 0 awk "{print / $$ A}" 1.txt awk / {print / / $$ A /} 1.txt awk '{print $' $ A '}' 1.txt awk '{print $ '"$ A"'} '1.txt # Note: "$ a" package in Soft Quote
Perhaps, you can mention more solutions .... ^ _ ^