Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| linux:bash [2026/01/11 11:57] – [Control Operators] mh | linux:bash [2026/10/31 22:42] (current) – [claude] fix command expansion, tilde and echo examples, heading levels, https link, typos claude | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| Bash can be used **interactively** in the terminal emulator or **non-interactively** as a written script of commands that is executed. | Bash can be used **interactively** in the terminal emulator or **non-interactively** as a written script of commands that is executed. | ||
| - | When bash starts a program, the system creates a running **process** for it. Bash creates **file descriptors** | + | When bash starts a program, the system creates a running **process** for it. Bash creates **file descriptors** |
| Bash has **synchronous command execution** meaning it will execute commands one at a time and users cannot interact with bash while it is executing a command. | Bash has **synchronous command execution** meaning it will execute commands one at a time and users cannot interact with bash while it is executing a command. | ||
| Line 157: | Line 157: | ||
| Because the file did not exist, the '' | Because the file did not exist, the '' | ||
| + | |||
| ===== Arguments ===== | ===== Arguments ===== | ||
| Line 162: | Line 163: | ||
| **Arguments are a sequence of characters considered as a single unit by the shell.** | **Arguments are a sequence of characters considered as a single unit by the shell.** | ||
| - | They can be a filename, a variable name, the name of a program or just a litteral. | + | They can be a filename, a variable name, the name of a program or just a literal. |
| Multiple arguments can be used, separated by a blank space | Multiple arguments can be used, separated by a blank space | ||
| Line 173: | Line 174: | ||
| Escaping is the act of adding a single \ before the character we want to escape. | Escaping is the act of adding a single \ before the character we want to escape. | ||
| - | Quoting is a better practice than escaping and should be use more often than not. Quoting is sometimes unnecessary but it is rarely wrong to quote. | + | Quoting is a better practice than escaping and should be used more often than not. Quoting is sometimes unnecessary but it is rarely wrong to quote. |
| <WRAP round important> | <WRAP round important> | ||
| Line 192: | Line 193: | ||
| $ read -p 'Which user would you like to remove from your system? ' username | $ read -p 'Which user would you like to remove from your system? ' username | ||
| Which user would you like to remove from your system? | Which user would you like to remove from your system? | ||
| - | #Note that the user accidentaly inputed | + | #Note that the user accidentally entered |
| $ rm -vr / | $ rm -vr / | ||
| Line 253: | Line 254: | ||
| <code bash> | <code bash> | ||
| - | $ contents=" | + | $ contents=" |
| # Don't forget to " | # Don't forget to " | ||
| </ | </ | ||
| Line 265: | Line 266: | ||
| <code bash> | <code bash> | ||
| $ name=mh time=8 | $ name=mh time=8 | ||
| - | $ echo " | + | $ echo " |
| mh, it is 8h. | mh, it is 8h. | ||
| </ | </ | ||
| Line 275: | Line 276: | ||
| === WHITESPACE === | === WHITESPACE === | ||
| - | Whitespace in bash have a special meaning : they split commands into arguments. | + | Whitespace in bash has a special meaning : they split commands into arguments. |
| === * === | === * === | ||
| - | A star or asterix | + | A star or asterisk |
| ---- | ---- | ||
| Line 311: | Line 312: | ||
| ==== Tilde expansion ==== | ==== Tilde expansion ==== | ||
| - | **Tilde expansion** happens earlier in the parser | + | **Tilde expansion** happens earlier in the parser |
| It is always replaced by an explicit pathname pointing to the home directory of the user or of another user explicitly named after the tilde. | It is always replaced by an explicit pathname pointing to the home directory of the user or of another user explicitly named after the tilde. | ||
| Line 320: | Line 321: | ||
| $ echo ~root | $ echo ~root | ||
| - | /var/root | + | /root |
| </ | </ | ||
| - | ===== Value Expansions ==== | + | ===== Value Expansions |
| **Command expansions** are a very useful value expansion example. You can call a command within a command by using $(...) syntax. | **Command expansions** are a very useful value expansion example. You can call a command within a command by using $(...) syntax. | ||
| Line 338: | Line 339: | ||
| You must **always** use " | You must **always** use " | ||
| </ | </ | ||
| + | |||
| ===== Redirection ===== | ===== Redirection ===== | ||
| Line 400: | Line 402: | ||
| <code bash> | <code bash> | ||
| #This convenience sugar syntax exists for directing both FD1 & FD2 to the same location | #This convenience sugar syntax exists for directing both FD1 & FD2 to the same location | ||
| - | $ping 127.0.0.1 &> | + | $ ping 127.0.0.1 &> |
| </ | </ | ||
| Line 407: | Line 409: | ||
| ==== Append to a file ==== | ==== Append to a file ==== | ||
| - | Use double | + | Use double |
| <code bash> | <code bash> | ||
| echo Hello > | echo Hello > | ||
| Line 413: | Line 415: | ||
| </ | </ | ||
| ---- | ---- | ||
| + | |||
| ===== Bash Scripting ===== | ===== Bash Scripting ===== | ||
| - | === Hashbangs === | + | ==== Hashbangs |
| To make a script out of a file containing bash commands, add a hashbang at the beginning of the file : | To make a script out of a file containing bash commands, add a hashbang at the beginning of the file : | ||
| Line 441: | Line 444: | ||
| Command names with a slash are always considered direct pathnames to the program to execute. | Command names with a slash are always considered direct pathnames to the program to execute. | ||
| </ | </ | ||
| - | ===== Ressources | + | |
| + | ===== Resources | ||
| *[[https:// | *[[https:// | ||
| *[[https:// | *[[https:// | ||
| *[[https:// | *[[https:// | ||
| - | *[[http:// | + | *[[https:// |