linux:bash
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:bash [2026/04/15 14:49] – [WILDCARD METACHARACTERS & EXPANSION] v1ctor | linux:bash [2026/05/15 13:30] (current) – [REDIRECTS vs PIPES] v1ctor | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| Core wildcards: | Core wildcards: | ||
| * * - zero or more characters. Example: '' | * * - zero or more characters. Example: '' | ||
| - | * ? - exactly one character. Example: '' | + | * ? - exactly one character. Example: '' |
| + | |||
| + | For example, following commands prints a list of files in the current directory: | ||
| + | <code bash> | ||
| + | $ echo * | ||
| + | </ | ||
| + | |||
| + | What's happening: | ||
| + | - Globbing (before echo runs) - The shell — not echo — expands * by looking at the current directory and replacing * with a space-separated list of matching filenames. | ||
| + | |||
| + | **Disabling expansion** | ||
| + | * If you don’t want the shell to expand a glob in a command, enclose the glob in single quotes (' '). For example, the command echo ' | ||
| + | * This might be useful when running commands like '' | ||
| + | * The reason why '' | ||
| ==== HERE DOCUMENTS ==== | ==== HERE DOCUMENTS ==== | ||
| Line 36: | Line 49: | ||
| </ | </ | ||
| - | ==== FILESYSTEM | + | ==== ENVIRONMENT VARIABLEs |
| + | |||
| + | Environment variables are named values stored by the shell/OS that processes can read to configure their behavior. Think of them as a key-value store available to every running program. | ||
| + | |||
| + | Environment variables are **not** global system state. They are per-process (and inherited downward only). | ||
| + | |||
| + | Setting an env variable for the current session: | ||
| + | <code bash> | ||
| + | export STUFF=blah | ||
| + | </ | ||
| + | |||
| + | To make env variable permanent, you need to store it in a file. Which file - depends on the Shell type: | ||
| + | |||
| + | Type of Shells: | ||
| + | |||
| + | ^ Shell Type ^ When it starts ^ Example ^ Reads file ^ | ||
| + | | Login Shell | You authenticate (SSH, TTY login, su -, bash -l) | SSH into a server | ~/.profile | | ||
| + | | Interactive non-login | You open a new terminal in an existing session | New tab in your terminal | ||
| + | |||
| + | * **~/ | ||
| + | * export PATH=..., export EDITOR=vim | ||
| + | * **~/ | ||
| + | * aliases, shell functions, prompt | ||
| + | |||
| + | |||
| + | ==== REDIRECTS vs PIPES ==== | ||
| + | |||
| + | The core difference: redirects connect a stream to a file (a redirect always has a file on one side). Pipes connect one process to another process. | ||
| + | |||
| + | |||
| + | Pipes: process → process: | ||
| + | <code bash> | ||
| + | cmd1 | cmd2 # Takes cmd1's stdout and feeds it directly into cmd2's stdin. No file involved | ||
| + | ls | grep " | ||
| + | </ | ||
| + | ==== STANDARD INPUT and OUTPUT ==== | ||
| + | |||
| + | Unix programs have 1 input and 2 outputs. | ||
| + | |||
| + | When you run a command from a terminal, they all go to/from the terminal by default, e.g.: | ||
| + | <code bash> | ||
| + | $ cat | ||
| + | hello # Stdin is connected to the terminal, you can type there. | ||
| + | hello # Stdout - cat prints it right away after you pressed enter. | ||
| + | </ | ||
| + | ** < redirects Stdin** | ||
| <code bash> | <code bash> | ||
| - | stat file.txt # shows additional details of the file (when created/ | + | cat < foo.txt |
| + | bar | ||
| </ | </ | ||
linux/bash.1776264598.txt.gz · Last modified: by v1ctor
