Skip to content

Intro to bash with real-world examples and command-line tips

License

Notifications You must be signed in to change notification settings

codenameyau/intro-to-bash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

intro-to-bash

Recommended Resources

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.

# 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.

# 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.

cat='sunny'
lol='hello $cat'
echo "$lol"

# prints
# hello $cat
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' ]].

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"

About

Intro to bash with real-world examples and command-line tips

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published