Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 30 days 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-15T13:22:38.000Z (about 5 years ago)
- Last Synced: 2024-08-04T01:10:16.151Z (3 months ago)
- Topics: bash, ci, linux
- Size: 41 KB
- Stars: 9
- Watchers: 2
- 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"
```