You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+35-33Lines changed: 35 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,9 +75,9 @@ The project lies at the intersection of C programming and system programming. Ev
75
75
- POSIX: A family of open system standards based on Unix.
76
76
- Builtin: A command that is implemented internally by the shell itself, rather than by an executable program somewhere in the file system.
77
77
- Operator: A control operator or a redirection operator.
78
-
- Control operator: A token that performs a control function. It is a newline or one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘;&’, ‘;;&’, ‘|’, ‘|&’, ‘(’, or ‘)’.
79
-
- Redirection operator: A token redirects input and out put to and from files by manipulating file descriptors: '<', '>', '>>', '&>'
80
-
- Heredoc: '<<'
78
+
- Control operator: A token that performs a control function. It is a newline or one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘;&’, ‘;;&’, ‘|’, ‘|&’, ‘(’, or ‘)’.
79
+
- Redirection operator: A token redirects input and out put to and from files by manipulating file descriptors: '<', '>', '>>', '&>'
80
+
- Heredoc: '<<'
81
81
- Exit status: The value returned by a command to its caller. The value is restricted to eight bits, so the maximum value is 255.
82
82
- Metacharacter: A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.
83
83
- Reserved word: A word that has a special meaning to the shell. Most reserved words introduce shell flow control constructs, such as 'for' and 'while'. (not strictly enforced by the shell)
@@ -125,11 +125,11 @@ A formal grammar takes a set of atomic pieces it calls its “alphabet”. Then
125
125
126
126
A grammar naturally describes the hierarchical structure of most programming language constructs. For example, an if-else statement in Java can have
127
127
128
-
```if (expression) statement else statement```
128
+
`if (expression) statement else statement`
129
129
130
130
That is, an if-else statement is the concatenation of the keyword if, an opening parenthesis, an expression, a closing parenthesis, a statement, the keyword else, and another statement. Using the variable expr to denote an expression and the variable stmt to denote a statement, this structuring rule can be expressed as
131
131
132
-
```stmt →if (expr) stmt else stmt```
132
+
`stmt →if (expr) stmt else stmt`
133
133
134
134
If you start with the rules, you can use them to generate strings that follow the grammar. Strings created this way are called derivations because each is “derived” from the rules of the grammar. In each step, you pick a rule and follow what it tells you to do. Most of the lingo around formal grammars comes from implementing them in this direction. Rules are called productions because they produce strings in the grammar.
135
135
Each production in a context-free grammar has a head—its name—and a body which describes what it generates. In its pure form, the body is simply a list of symbols. Symbols come in two delectable flavors:
@@ -155,8 +155,8 @@ Some of the tokens that are of interest to us:
155
155
| blank | A space or tab character. |
156
156
| word | A sequence of characters considered as a single unit by the shell. Also known as a token. |
157
157
| name | A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an identifier. |
158
-
| metacharacter | A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: '\|', '&', ';', '(', ')', '<', or '>'. |
159
-
| control operator | A token that performs a control function. It is a newline or one of the following: '\|\|', '&&', '&', ';', ';;', ';&', ';;&', '\|', '\|&', '(', or ')'. |
158
+
| metacharacter | A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: '|', '&', ';', '(', ')', '<', or '>'. |
159
+
| control operator | A token that performs a control function. It is a newline or one of the following: '||', '&&', '&', ';', ';;', ';&', ';;&', '|', '|&', '(', or ')'. |
160
160
| operator | A sequence of characters considered a single unit by the shell. It is either a word or an operator. |
161
161
| reserved word | A word that has a special meaning to the shell. Most reserved words introduce shell flow control constructs, such as loops or conditionals. The reserved words recognized by the shell are: `! case esac do done if elif else fi for in then until while { } time [[ ]]`
162
162
@@ -454,12 +454,12 @@ Redirection operators in Bash allows the user to manipulate where a command read
454
454
4.**`<<` (Here Document):**
455
455
- Allows you to pass multiple lines of input to a command.
456
456
- Example:
457
-
```bash
457
+
```bash
458
458
cat <<EOF
459
459
Line 1
460
460
Line 2
461
461
EOF
462
-
```
462
+
```
463
463
This command uses a here document to pass multiple lines to the `cat` command.
464
464
465
465
From the Bash manual:
@@ -470,7 +470,7 @@ Redirection must be distinguished from "Process substitution", which "allows a p
470
470
471
471
Effectively, the redirection symbols are followed by a filename (or word that is expanded to a file name), which is opened forwriting ('>'), writing and appending ('>>') or reading ('<') and its file descriptor then duplicated to act as stdout ('>' and '>>') or stdin ('<') depending on the redirection. Soin a command comprised of several tokens, containing redirection symbols, each redirection token and the token to the right of it are interpreted, opening attempted of the file specified and file descriptor(s) duplicated. The remaining token are then passed on for execution.
472
472
A fun illustration:
473
-
```echo hello > world here I am```
473
+
`echo hello > world here I am`
474
474
In this case stdout is redirected to the file "world", which is created if does not exist and then the rest of the command is executed. As a result the file world contains the string "hello here I am".
475
475
476
476
### Pipes
@@ -635,73 +635,73 @@ Some examples of using `&&` (logical AND) and `||` (logical OR) with parentheses
635
635
### Using `&&` (Logical AND):
636
636
637
637
1. **Basic `&&` Example:**
638
-
```bash
638
+
```bash
639
639
command1 && command2
640
-
```
640
+
```
641
641
- If `command1` succeeds (returns a zero exit status), then `command2` will be executed.
642
642
643
643
2. **Multiple Commands with `&&`:**
644
-
```bash
644
+
```bash
645
645
(command1 && command2) && command3
646
-
```
646
+
```
647
647
- `command1` and `command2` are executed in sequence. If both succeed, then `command3` is executed.
648
648
649
649
3. **Mixing `&&` and `||`:**
650
-
```bash
650
+
```bash
651
651
(command1 && command2) || command3
652
-
```
652
+
```
653
653
- If `command1` and `command2` succeed, then `command3` will not be executed. If either `command1` or `command2` fails, then `command3` will be executed.
654
654
655
655
### Using `||` (Logical OR):
656
656
657
657
1. **Basic `||` Example:**
658
-
```bash
658
+
```bash
659
659
command1 || command2
660
-
```
660
+
```
661
661
- If `command1` fails (returns a non-zero exit status), then `command2` will be executed.
662
662
663
663
2. **Multiple Commands with `||`:**
664
-
```bash
664
+
```bash
665
665
(command1 || command2) || command3
666
-
```
666
+
```
667
667
- `command1` is executed. If it fails, then `command2` is executed. If both fail, then `command3` is executed.
668
668
669
669
3. **Mixing `&&` and `||`:**
670
-
```bash
670
+
```bash
671
671
(command1 || command2) && command3
672
-
```
672
+
```
673
673
- If `command1` succeeds, then `command2` will not be executed, and `command3` will be executed. If `command1` fails, then `command2` is executed, and `command3` will not be executed.
674
674
675
675
Wildcards, such as `*`, are used for pattern matching in file names. Here are some examples of using wildcards in the current working directory:
676
676
677
677
1. **List all files in the current directory:**
678
-
```bash
678
+
```bash
679
679
ls *
680
-
```
680
+
```
681
681
- This command lists all files (and directories) in the current directory.
682
682
683
683
2. **Remove all text files in the current directory:**
684
-
```bash
684
+
```bash
685
685
rm *.txt
686
-
```
686
+
```
687
687
- This command removes all files with a `.txt` extension in the current directory.
688
688
689
689
3. **Copy all `.jpg` files to another directory:**
690
-
```bash
690
+
```bash
691
691
cp *.jpg /path/to/destination/
692
-
```
692
+
```
693
693
- This command copies all files with a `.jpg` extension to the specified destination directory.
694
694
695
695
4. **Count the lines in all `.log` files:**
696
-
```bash
696
+
```bash
697
697
wc -l *.log
698
-
```
698
+
```
699
699
- This command counts the number of lines in each file with a `.log` extension in the current directory.
700
700
701
701
5. **Grep for a specific pattern in all `.md` files:**
702
-
```bash
702
+
```bash
703
703
grep "pattern" *.md
704
-
```
704
+
```
705
705
- This command searches for the specified pattern in all files with a `.md` extension.
706
706
707
707
These examples demonstrate how wildcards can be used in combination with various commands for file manipulation and processing in the current working directory.
0 commit comments