Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| linux:bash [2022/02/28 14:15] – [Arguments] mh | linux:bash [2026/01/11 11:57] (current) – [Control Operators] mh | ||
|---|---|---|---|
| Line 113: | Line 113: | ||
| ---- | ---- | ||
| + | === 2>/ | ||
| + | |||
| + | <code bash> | ||
| + | $ something 2>/ | ||
| + | </ | ||
| + | |||
| + | This means: | ||
| + | |||
| + | Try something, but if it errors (exit code ≠ 0): | ||
| + | * silence the error message (send to ''/ | ||
| + | * immediately run '' | ||
| + | * Overall '' | ||
| + | |||
| + | In plain English: | ||
| + | |||
| + | “Try to do the cleanup. | ||
| + | If there’s nothing to clean, that’s fine. Move on.” | ||
| + | |||
| + | This pattern is **not appropriate** when: | ||
| + | * Failure is meaningful | ||
| + | * You want to be alerted | ||
| + | * Data loss is possible | ||
| + | * You are debugging | ||
| + | |||
| + | In those cases, we want '' | ||
| + | |||
| + | So this is not about hiding problems. | ||
| + | It’s about acknowledging expected non-problems. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | === && AND Operator === | ||
| + | |||
| + | This control operator tells bash to run a second command **only if the first command before it succeeded**. | ||
| + | |||
| + | If the first command fails, the second command is entirely skipped. | ||
| + | |||
| + | **Example** | ||
| + | <code bash> | ||
| + | $ rm hello.txt && echo " | ||
| + | rm: cannot remove ' | ||
| + | </ | ||
| + | |||
| + | Because the file did not exist, the '' | ||
| ===== Arguments ===== | ===== Arguments ===== | ||
| Line 203: | Line 247: | ||
| There can be **no whitespace** around the = operator ! | There can be **no whitespace** around the = operator ! | ||
| - | If a whitespace is required in the variable, use '' | + | If a whitespace is required in the variable, use 'single |
| </ | </ | ||
| Line 343: | Line 387: | ||
| As a result, both file descriptors are connected to the same stream. | As a result, both file descriptors are connected to the same stream. | ||
| + | Be careful not to write something like '' | ||
| </ | </ | ||