|
| 1 | +Bash executes a 5-step process before execute a command. |
| 2 | + |
| 3 | +## 1) Tokenization : |
| 4 | + |
| 5 | +After Tokenization the whole command divides into parts. Each of the part is either 'word' or 'operator'. |
| 6 | + |
| 7 | +### Word doesn't contain any unquoted meta-character |
| 8 | +### Operator containes at least one unquoted meta-character |
| 9 | + |
| 10 | +So here, the meaning of unquoted meta-character plays the vital role to distiguish between words & operators. |
| 11 | + |
| 12 | +In linux, There are total of 10 punctuations that are known as metaCharacters. They are :: <br> |
| 13 | + | & ; ( ) < > space tab newLine |
| 14 | + |
| 15 | +We also need to know the meaning of 'unquoted' too. There are 3 types of quoting (means Removing special meaning) in linux. They are :: <br> |
| 16 | + |
| 17 | +i) \ -> Removing special meaning of next character <br> |
| 18 | +ii) '' -> Removing special meaning of all the characters inside <br> |
| 19 | +iii) "" -> Removing special meaning of all the characters inside, except dollar($) and backtick(`). |
| 20 | + |
| 21 | +So In simple, If you find any of the 10 metaCharacters, that has not been quoted in any of the above three ways, Thats an operator !! |
| 22 | + |
| 23 | + |
| 24 | +## 2) Command Identification : |
| 25 | + |
| 26 | +There are two types of commands. Simple & Compound. To distinguish between them, We need a good understanding of operators. As we already know what actually operators are, lets divide them into different types : |
| 27 | + |
| 28 | +a) Control operators : <br> |
| 29 | +| || & && ; ;; ;& ;;& |& ( ) newLine |
| 30 | + |
| 31 | +b) Redirection operators : <br> |
| 32 | +< > << >> <& >& <> <<- >| |
| 33 | + |
| 34 | +Look carefully that, redirection operators always either < or >. Also, space and tab are just separators. They dont have effect on controlling or redirecting. |
| 35 | + |
| 36 | +## 3) Expansion : |
| 37 | + |
| 38 | +As this stage is a very big and complex, it generally divided into 4 steps. |
| 39 | +### a) Brace Expansion : |
| 40 | +It will be easier to understand this by example, rather than explanation. |
| 41 | + |
| 42 | +echo {a,b,42,arnob}_xyz # prints a_xyz b_xyz 42_xyz arnob_xyz <br> |
| 43 | +echo {1..5} # prints 1 2 3 4 5 <br> |
| 44 | +echo {z..a..5} # prints z u p k f a <br> |
| 45 | +mkdir -p path/{ucb/{ex,edit},lib/{ext,abc}} # make directories .. <br>path/lib/abc , path/lib/ext , path/ucb/edit , path/ucb/ex |
| 46 | + |
| 47 | +### b) Intermidiate Expansion : |
| 48 | + |
| 49 | +### c) Word splitting : |
| 50 | + |
| 51 | +### d) Globbing : |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +## 4) Quote Removal : |
| 57 | + |
| 58 | +## 5) Redirection : |
0 commit comments