my c code
comment # 2
How do I put multi line comment under a shell script? Can you tell method to set multiline shell script comments?
# my comment goes here
Bash Shell Script Put Multiple Line Comment Syntax
For multiline comment use the following syntax:
#!/usr/bin/env bash # my comment 1 # my comment 2 # my comment N
However, you can use HERE DOCUMENT feature as follows:
#!/bin/bash echo "Say Something" <<COMMENT1 your comment 1 comment 2 blah COMMENT1 echo "Do something else"
This type of redirection tells the shell to read input from the current source (HERE) until a line containg only word (HERE) is seen. HERE word is not subjected to variable name, parameter expansion, arithmetic expansion, pathname expansion, or command substitution. All of the lines read up to that point are then used as the standard input for a command. Files are processed in this manner are commonly called here documents. If you do not want variable name, parameter expansion, arithmetic expansion, pathname expansion, or command substitution quote HERE (COMMENTS) in a single quote:
<<'COMMENTS' text1 text2 testN $varName COMMENTS
Bash comment block example
It is important that you put EOF in a single quote ('EOF') to avoid command execution and phrasing. Here is block comments in a shell script example:
#!/usr/bin/env bash echo "*** Before comment block ***" : <<'EOF' CODE block starts CODE block ends here EOF echo "*** After comments block ***"
Multiline shell script comments
Another option as pointed out by Ikram in the comments section below:
#!/bin/bash foo=bar : ' This is a test comment Author foo bar Released under GNU ' echo "Init..." # rest of script
Please note that the : is shell builtin command. From the bash(1) man page:
: [arguments] No effect; the command does nothing beyond expanding arguments
and performing any specified redirections. A zero exit code is
So the syntax is:
: ' your comments here '
Null command used in your shell script to put multiple comments. The ':' has no effect. In other words, the command does nothing and it always exit with succeed code.
It would be best if you documented your script and writing comments considered as a best practice. Other sysadmins and developers might use comments to understand your scripts. As explained eariler, anything is written after # and till the end of the line is nothing but comments.
You learned about multiline shell script comments possibilities. However, shells do not offer a multiline comment syntax. Hence, we learned and used various techniques such as here-documents to make multiline "comments" under Linux or Unix-like systems.
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|