Comments
Part of the Fundamentals section of Coddy's Terminal journey. Lesson 3 of 82.
Comments are lines in your shell script that are ignored by the shell. They are used to add notes and explanations to your code for human understanding.
In the shell, a comment starts with a # at the start of a line or after a space. Everything from that # to the end of the line is ignored:
# This is a comment
echo "Hello!" # This also prints Hello!When you run the above, only Hello! is printed: the comments are completely invisible to the shell.
A # inside quotes or in the middle of a word does not start a comment: echo "Issue #5" prints Issue #5.
Common uses for comments:
1. Explaining what a command does:
# Print a welcome message
echo "Welcome to the terminal!"2. Disabling a command temporarily:
# echo "This line is disabled"
echo "This line will execute"3. The Shebang line:
A special comment at the very top of a shell script tells the system which shell to use:
#!/bin/bash
echo "This script runs with Bash"This line starts with #! (called a shebang) followed by the path to the shell. It is always the first line of a script.
4. TODO Comments: mark future tasks:
# TODO: Add error handling here
echo "Processing files..."Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data PipelinePractice on your own: Terminal playground