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 the # symbol. Everything after # on that 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.
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..."Cheat sheet
Comments in shell scripts start with # and are ignored by the shell:
# This is a comment
echo "Hello!" # Inline commentShebang: A special comment at the top of a script specifying which shell to use:
#!/bin/bashComments can be used to explain code, disable commands temporarily, or mark future tasks with TODO.
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 Pipeline