Introduction
Good style and conventions make your scripts easy to read and fix. They help others understand your work quickly.
Good style and conventions make your scripts easy to read and fix. They help others understand your work quickly.
# Use comments to explain your code # Use lowercase for variable names variable_name="value" # Use indentation for readability if [ "$variable_name" = "value" ]; then echo "It matches" fi
Comments start with # and explain what the code does.
Use lowercase letters and underscores for variable names to keep them clear.
# Good comment style # This script prints a greeting name="Alice" echo "Hello, $name!"
# Use clear variable names user_age=30 if [ "$user_age" -ge 18 ]; then echo "Adult" fi
# Indent inside conditions if [ "$name" = "Bob" ]; then echo "Hi Bob!" else echo "Who are you?" fi
This script uses comments, clear variable names, and indentation to make it easy to read.
#!/bin/bash # This script checks if a user is an adult user_name="Charlie" user_age=20 # Check age if [ "$user_age" -ge 18 ]; then echo "$user_name is an adult." else echo "$user_name is not an adult." fi
Always start scripts with #!/bin/bash to specify the shell.
Keep lines short and clear for easy reading.
Use comments to explain why, not what, when the code is obvious.
Use comments to explain your script.
Choose clear, lowercase variable names with underscores.
Indent code blocks to show structure.
file_count uses lowercase and underscores, which is clear and readable. Other options use spaces, uppercase, or numbers only, which are not recommended.file_count -> Option A# symbol to start a comment line.#, which is correct. Options B, C, and D use comment styles from other languages.count=3 if [ $count -gt 0 ]; then echo "Count is positive" fi
count is 3, which is greater than 0, so the condition [ $count -gt 0 ] is true.echo "Count is positive", printing that line.for i in 1 2 3 do echo $i done
for i in 1 2 3; do ... done. The newline before do is allowed.do keyword is present. No semicolon needed before newline.Pass the test and this pattern moves unknown