0
0
Bash Scriptingscripting~5 mins

Style guide and conventions in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
Why should you use comments in bash scripts?
Comments explain what the script or parts of it do. They help others and your future self understand the code easily.
Click to reveal answer
beginner
What is the recommended way to name variables in bash scripts?
Use uppercase letters with underscores, like MY_VARIABLE. This makes variables easy to spot and avoids conflicts with system variables.
Click to reveal answer
intermediate
Why should you use double quotes around variables in bash scripts?
Double quotes prevent word splitting and globbing, which can cause unexpected behavior when variables contain spaces or special characters.
Click to reveal answer
intermediate
What is the purpose of using 'set -e' at the start of a bash script?
'set -e' makes the script stop immediately if any command fails. This helps catch errors early and avoid running wrong commands.
Click to reveal answer
beginner
How should you format your bash script for readability?
Use indentation for blocks like loops and conditionals, add blank lines between sections, and keep lines short. This makes the script easier to read and maintain.
Click to reveal answer
What is the best way to name variables in bash scripts?
ANumbers only (e.g., 123)
BLowercase letters without underscores (e.g., myvar)
CMixed case with spaces (e.g., My Var)
DUppercase letters with underscores (e.g., MY_VAR)
Why should you put double quotes around variables in bash scripts?
ATo comment out the variable
BTo make variables bold
CTo prevent word splitting and globbing
DTo convert variables to uppercase
What does 'set -e' do in a bash script?
AStops the script if any command fails
BEnables verbose output
CIgnores all errors
DRuns the script in the background
Which of these is a good practice for bash script readability?
AUse random variable names
BUse indentation and blank lines
CAvoid comments
DWrite all code in one long line
Why add comments in your bash scripts?
ATo explain what the code does
BTo make the script run faster
CTo hide code from the shell
DTo change variable names
Explain three key style guide rules you should follow when writing bash scripts.
Think about naming, quoting, and documentation.
You got /3 concepts.
    Describe how formatting and error handling improve bash script quality.
    Consider readability and safety.
    You got /3 concepts.