https://github.com/codenameyau/intro-to-bash
Intro to bash with real-world examples and command-line tips
https://github.com/codenameyau/intro-to-bash
bash ci linux
Last synced: about 1 year ago
JSON representation
Intro to bash with real-world examples and command-line tips
- Host: GitHub
- URL: https://github.com/codenameyau/intro-to-bash
- Owner: codenameyau
- License: gpl-3.0
- Created: 2019-08-06T20:32:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-15T13:22:38.000Z (over 6 years ago)
- Last Synced: 2025-04-13T14:09:52.916Z (about 1 year ago)
- Topics: bash, ci, linux
- Size: 41 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# intro-to-bash
Recommended Resources
- Official GNU reference: https://www.gnu.org/software/bash/manual/html_node/index.html
- Bash Guide for Beginners: https://www.tldp.org/LDP/Bash-Beginners-Guide/html/
## Hot Tips
### How to use variables correctly
Spacing is critical in bash since commands are separated by spaces.
Assignments, for example, should be done without spaces.
```sh
# Bad. Interprets line as 3 separate commands.
var = 'lol'
# Good. Will assign 'lol' to var.
var='lol'
```
Always use `lower_case` for local variables and `UPPER_CASE` for environment variables.
```sh
# local variable.
my_local_variable='lol'
# environment variable.
export MY_ENV_VARIABLE='lol'
```
Always use **single quotes for string literals** and **double quotes for interpolated strings**.
```sh
cat='sunny'
lol='hello $cat'
echo "$lol"
# prints
# hello $cat
```
```sh
cat='sunny'
lol="hello $cat"
echo "$lol"
# prints
# hello sunny
```
Always double quote variables unless you know what you're doing. The only exceptions
are for loops and the test expression syntax with double brackets, e.g. `[[ $name = 'cat' ]]`.
```sh
words="good boy does fine"
# Bad. Executes 4 separate commands with 1 word arg.
ls $words
# Good. Executes a single command with 4 args.
ls "$words"
```